%% Demo of modefilt2.m %% (Requires Image Processing Toolbox) %% Code by: Shawn Lankton, April 2008. (www.shawnlankton.com) %-- load original data. Here, '0' represents bad pixels load p; %-- built-in medfilt medfilt = medfilt2(p,[11 11]); %-- modefilt without ignoring anything. Here, a window of 5x5 is % equivalent to a 11x11 window with the built-in medfilt function modefilt = modefilt2(p,[5 5]); %-- modefilt ignoring pixels below 1. Hence, all "bad" pixels are ignored % when computing local modes. modefilt_selective = modefilt2(p,[5 5],1); %-- Display results figure(100) subplot(2,2,1), imshow(p,[5 17]); title('original') subplot(2,2,2), imshow(medfilt,[5 17]); colormap jet; title('median filtered') subplot(2,2,3), imshow(modefilt_selective,[5 17]); colormap jet; title('selective mode filtered') subplot(2,2,4), imshow(modefilt,[5 17]); colormap jet; title('mode filtered')