function imOut = medianFilter(imIn,windowWidth)
if mod(windowWidth, 2 ) == 0
disp('Window has even size');
return
end
imageSize = size(imIn);
imOut = imIn;
windowBreadth = (windowWidth - 1)/2;
for m=windowBreadth+1:imageSize(1) - windowBreadth
for n=windowBreadth+1:imageSize(2) - windowBreadth
t1 = imIn(m-windowBreadth:m+windowBreadth,n-windowBreadth:n+windowBreadth);
t2 = reshape(t1,windowWidth*windowWidth,1);
t3 = median(t2);
imOut(m,n) = t3;
end
end
my explanation:
the function medianFilter takes an image(imIn) as an input, and a width for the window of the median filter
then I’m not sure why we need the if statement
after that we take the size of the input image and save it in a variable called imageSize
then we copy all the values of imIn to imOut
then I’m all lost
what is windowbreadth? and isn’t breadth and width the same thing?
thanks!
The
ifconditional is checking that the window-size is odd; if it’s even then there is no “central” pixel.windowbreadthseems like a bad name. But its meaning should be clear from the diagram below:where
Sis the window-size,Bis the window-“breadth”, and*denotes the “central” pixel.So
t1is all the samples in the current window.t2is those samples rearranged as a 1D vector rather than a 2D array.