B = nlfilter(A,'indexed',___)
processes A as an indexed image, padding with
0s if the class of A is
uint8, uint16, or
logical, and padding with 1s
otherwise.
Note
nlfilter can take a long time to process large images.
In some cases, the colfilt function can perform the same
operation much faster.
This example shows how to apply a median filter to an image using nlfilter. This example produces the same result as calling medfilt2 with a 3-by-3 neighborhood.
Read an image into the workspace.
A = imread('cameraman.tif');
Convert the image to double.
A = im2double(A);
Create the function you want to apply to the image—a median filter.
fun = @(x) median(x(:));
Apply the filter to the image.
B = nlfilter(A,[3 3],fun);
Display the original image and the filtered image, side-by-side.
montage({A,B})
title('Original Image (Left) and Median Filtered Image (Right)')
Image to be filtered, specified as a numeric array of any class supported
by fun. When A is grayscale, it can be
any numeric type or logical. When A is
indexed, it can be logical, uint8,
uint16, single, or
double.
Block size, specified as a 2-element vector of positive integers.
m is the number of rows and n is
the number of columns in the block.
Example: B = nlfilter(A,[3 3],fun);
Data Types: single | double | logical
Function handle specified as a handle. The function must accept an
m-by-n matrix as input and return
a scalar result.
c = fun(x)
c is the output value for the center pixel in the
m-by-n block x.
nlfilter calls fun for each pixel
in A. nlfilter zero-pads the
m-by-n block at the edges, if
necessary.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.