2015-11-24 83 views
2

我運行了這段代碼,但由於某種原因,輸出是一個帶有黑色右邊框的白色屏幕。有誰知道爲什麼會發生?在matlab中應用並顯示平均濾波器

image=imread('lena.jpg'); 
image=rgb2gray(image); 
[rows,cols]=size(image); 
paddedimage=padarray(image,[1 1]); 
newimage=zeros(rows,cols); 
tot=0; 
for i=2:(rows-1) 

    for j=2:(cols-1) 
    for i1=i-1:i+1 
     for j1=j-1:j+1 
      jk=image(i1,j1); 
      tot=tot+jk; 
     end 

    end 
    tot=tot/9; 
    newimage(i-1,j-1)=tot; 
    end 
    tot=0; 
end 

imshow(newimage); 
+1

使用'imshow'前檢查newimage'的'的數據類型。它必須是'uint8',範圍從'0' - '255'(僅限整數)或'double'類型,範圍從'0' - '1'。 – Dan

+1

另外,任何你不只是使用'conv2'的理由?至少用它來檢查你自己 – Dan

回答

2

你需要告訴MATLAB 顯示範圍要使用的。您可以使用imshow(newimage, []);自動選擇。 輸出的內置演示圖像office_1.jpg:

imshow(newimage); 

enter image description here

imshow(newimage, []); 

enter image description here