2-D and 3-D mode filtering
performs
mode filtering on the 2-D image or 3-D volume B
= modefilt(A
)A
. Each output pixel in
B
contains the mode (most frequently occurring value) in the
neighborhood around the corresponding pixel in A
. If
A
is 2-D, modefilt
uses a 3-by-3 mode filter. If
A
is 3-D, modefilt
uses a 3-by-3-by-3 mode filter.
modefilt
pads A
by mirroring border
elements.
Mode filtering can be useful for processing categorical data, where other types of filtering, such as median filtering, are not available.
When the neighborhood has more than one pixel in a tie for the mode value, the function uses the following tie-breaking algorithm:
If the center pixel is one of the mode values in the tie, the function uses this value.
If the center pixel is not one of the mode values in the tie, the function uses the mode with the smallest numeric value.
For categorical input, the function chooses the first category (among the
categories tied for mode) that appears in the list returned by
categories(A)
.
modefilt
treats RGB images as 3-D volumes. To do channel-wise
filtering of an RGB image, specify filtsize
as [3 3
1]
, as in this code: b = modefilt(a,[3 3 1]);
.