Input = imread('baby1.jpeg') ; size(Input) P=rgb2gray(Input); image= im2double(P); [m n ] = size(A); Med = ; %Modified filter for i=2:m-1 for j=2:n-1 Med(1) = image(i,j); Med(2) =image(i-1,j) ; Med(3) = image(i-1,j+1); Med(4) = image(i,j-1); Med(5) = image(i,j+1); Med(6) = image(i+1, j-1); Med(7) = image(i+1,j); Med(8) = image(i+1,j+1); Afilteres(i, j) = median(Med(:)); end end imshow(Af);
In this the size of image varies
No products are associated with this question.
m = size(A); A1 = zeros([m(1:2) + 2,m(3)]); A1(2:end-1,2:end-1,:) = A; Af = zeros(m); for ii = 1:m(1) for jj = 1:m(2) k = reshape(A1(ii:ii+2,jj:jj+2,:),,1,3); Af(ii,jj,:) = median(k([1:4,6:9],:,:)); % EDIT end end
Of course the image sizes are different, because you're sliding a window along, and you have it so that when the edge of the window touches the edge of the image, it stops. So of course the output image will not be as big as the input image.
Again, I have demo code but since you said you're not allowed to use built in functions, and probably not code handed over to you in Answers or code you got from the File Exchange, I won't post it. Yeah, sometimes instructors/professors are picky about doing your own work.