Yara Adel Ahmed
Yara Adel Ahmed

Reputation: 21

Apply and display mean filter in matlab

I ran this code but for some reason the output is a white screen with a black right border. Does anyone know why that happens ?

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);

Upvotes: 2

Views: 66

Answers (1)

lhcgeneva
lhcgeneva

Reputation: 1981

You need to tell Matlab which display range to use. You can let it choose automatically by using imshow(newimage, []);. Output for the builtin demo image office_1.jpg:

imshow(newimage);

enter image description here

imshow(newimage, []);

enter image description here

Upvotes: 2

Related Questions