Sliding window minimum and maximum filter in MATLAB I'm trying to apply a sliding window minimum and maximum filter to an image of a certain window size. Actually, I'm trying to find the optimum window size for it. But I really haven't gotten the hang of it. I presume that I should be using blockproc to implement the sliding window, but not really sure how to find the maximum and minimum filter. As to the implementation itself, should I use loops to slide the window across the entire area of the image ?
ordfilt2 will do this for you: 

N=5;
filtered_img = ordfilt2(img, 1, true(N));


for minimum and

filtered_img = ordfilt2(img, N*N, true(N));


for the maximum.  You can also use imdilate and imerode to perform maximum and minimum filters.