www.gusucode.com > images 案例代码 matlab源码程序 > images/ApplyMedianFilterToImageExample.m

    %% Apply median filter to image
% This example shows how apply a median filter to an image using |nlfilter|
% . This example produces the same result as calling |medfilt2| with a
% 3-by-3 neighborhood.
%%

% Copyright 2015 The MathWorks, Inc.

A = imread('cameraman.tif'); 
A = im2double(A);
fun = @(x) median(x(:)); 
B = nlfilter(A,[3 3],fun); 
imshow(A), figure, imshow(B)