The MedianFilter object performs 2D median
filtering.

Construction

H = vision.MedianFilter returns
a 2D median filtering object, H. This object performs
two-dimensional median filtering of an input matrix.

H = vision.MedianFilter(Name,Value) returns
a median filter object, H, with each property set
to the specified value. You can specify additional name-value pair
arguments in any order as (Name1, Value1,...,NameN,ValueN).

H = vision.MedianFilter(SIZE,Name,Value) returns
a median filter object, H, with the NeighborhoodSize property
set to SIZE and other properties set to
the specified values.

Specify the size of the neighborhood over which the median filter
computes the median. When you set this property to a positive integer,
the integer represents the number of rows and columns in a square
matrix. When you set this property to a two-element vector, the vector
represents the number of rows and columns in a rectangular matrix.
The median filter does not support fixed-point properties when both
neighborhood dimensions are odd. The default is [3 3].

OutputSize

Output matrix size

Specify the output size as one of Same
as input size | Valid.
The default is Same as input size.
When you set this property to Valid,
the 2D median filter only computes the median where the neighborhood
fits entirely within the input image and requires no padding. In this
case, the dimensions of the output image are:

Otherwise, the object outputs the same dimensions as the input
image.

PaddingMethod

Input matrix boundary padding method

Specifies how to pad the boundary of the input matrix as one
of Constant | Replicate | Symmetric | Circular.
When you set this property to Constant,
the object pads the matrix with a constant value. When you set this
property to Replicate, the object
pads the input matrix by repeating its border values. When you set
this property to Symmetric, the
object pads the input matrix with its mirror image. When you set this
property to Circular the object
pads the input matrix using a circular repetition of its elements.
This property applies only when you set the OutputSize property
to Same as input size. The default
is Constant.

PaddingValueSource

Source of constant boundary value

Specifies how to define the constant boundary value as one of Property | Input
port. This property applies only when you set the PaddingMethod property
to Constant. The default is Property.

PaddingValue

Constant padding value for input matrix

Specifies a constant value to pad the input matrix. The default
is 0. This property applies only when you set the PaddingMethod property
to Constant and the PaddingValueSource property
to Property. This property is tunable.

Specify the rounding method as one of Ceiling | Convergent | Floor | Nearest | Round | Simplest | Zero.
The default is Floor. This property
applies only when the NeighborhoodSize property
corresponds to even neighborhood options.

OverflowAction

Overflow action for fixed-point operations

Specify the overflow action as one of Wrap | Saturate. The default is Wrap. This property is applies only when
the NeighborhoodSize property
corresponds to even neighborhood options.

AccumulatorDataType

Accumulator word and fraction lengths

Specify the accumulator fixed-point data type as one of Same as input | Custom.
The default is Same as input. This
property applies only when the NeighborhoodSize property
corresponds to even neighborhood options.

CustomAccumulatorDataType

Accumulator word and fraction lengths

Specify the accumulator fixed-point type as a scaled numerictype object with a Signedness of Auto.
This property applies only when the AccumulatorDataType property
is Custom and the NeighborhoodSize property
corresponds to even neighborhood options. The default is numerictype([],32,30).

OutputDataType

Output word and fraction lengths

Specify the output fixed-point data type as Same as inputor Custom.
This property applies only when the NeighborhoodSize property
corresponds to even neighborhood options. The default is Same as input.

CustomOutputDataType

Output word and fraction lengths

Specify the output fixed-point type as a scaled numerictype object with a Signedness of Auto.
This property applies only when the OutputDataType property
is Custom and the NeighborhoodSize property
corresponds to even neighborhood options. The default is numerictype([],16,15).

I = imread('pout.tif');
I = imnoise(I, 'salt & pepper')

Create a median filter object.

medianFilter = vision.MedianFilter([5 5]);

Filter the image.

I_filtered = step(medianFilter, I);

Display the results with a title.

figure; imshowpair(I, I_filtered, 'montage');
title('Noisy image on the left and filtered image on the right');

Algorithms

This object implements the algorithm, inputs, and outputs described
on the Median Filter block
reference page. The object properties correspond to the block parameters.