ORDFILT2 Example
From MATLAB Techniques for Image Processing by Steve Eddins.
An order-statistic filter replaces each pixel value by the k-th smallest value in that pixel's neighborhood. Sometimes you can creatively implement image processing operations by calling ordfilt2.
One example is a bright-pixel detector. How can we use order-statistic filtering to find all pixels that are least a certain amount higher than all of their neighbors?
Answer: By asking ordfilt2 to compute the second-brightest pixel value in each neighborhood.
I = imread('cameraman.tif'); imshow(I) xlabel('Image courtesy of MIT')

second_brightest = ordfilt2(I,24,ones(5, 5)); result = (I - second_brightest) > 10; imshow(result)
