Main Content

Median Filter

Perform 2-D median filtering

  • Library:
  • Computer Vision Toolbox / Analysis & Enhancement

    Computer Vision Toolbox / Filtering

  • Median Filter block

Description

TheMedian Filterblock applies a median filter to each pixel of an input image. For eachM-by-Nneighborhood, the filter replaces the central value with the median value of the neighborhood. If the neighborhood has a center element, the block replaces the center pixel with the median value, as shown in this figure.

If the neighborhood does not have an exact center, then the block has a bias toward the upper-left corner of the neighborhood. In this figure, the median value has been placed in the top-left pixel of the four pixels that meet at the center of the neighborhood.

The block pads the edges of the input image for filtering. This causes the pixels withinM/2pixels of the sides andN/2pixels of the top or bottom of the image to appear distorted.

The median value is less sensitive than the mean to extreme values. Thus,Median Filteris effective for removing salt-and-pepper noise from an image without significantly reducing the sharpness of the image.

Ports

Input

expand all

Input image, specified as anM-by-Nmatrix.

Data Types:single|double|int8|int16|uint8|uint16|Boolean|fixed point

Pad value, specified as a scalar. The block uses this value for each element of the rows or columns added to the input image.

Dependencies

To enable this port:

  • Set theOutput sizeparameter toSame as input port I.

  • Set thePadding optionsparameter toConstant.

  • Set thePad value sourceparameter toInput port.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|Boolean

Output

expand all

Output image, returned as a matrix. The dimensions of the median-filtered output image are specified by theOutput sizeparameter.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|Boolean|fixed point

Parameters

expand all

Specify the window size of the neighborhood over which the block computes the median. If specified as a scalar, this value creates a square neighborhood with the specified number of rows and columns. If specified as a vector, the first element is the number of rows in the neighborhood, and the second element is the number of columns in the neighborhood.

Specify the output sizing method as one of these options.

  • Same as input port I— The block computes the neighborhood median for the entire image, using padding to compute the boundary pixels. The output image has the same dimensions as the input image. Selecting this option enables thePadding optionsparameter.

  • Valid— The block computes the median where the neighborhood fits within the input image without padding. For an input image of sizeM-by-Nand neighborhood of sizeX-by-Y, the output image has the dimensions (MX+1)-by-(NY+1).

Pad the image using one of these methods:

Dependencies

To enable this parameter, set theOutput sizeparameter toSame as input port I.

Specify the padding source asSpecify via dialogorInput port.

  • Specify via dialog— Specify a padding value using thePad valueparameter.

  • Input port— Specify a padding value using thePValinput port.

Dependencies

To enable this parameter, set theOutput sizeparameter toSame as input port I, and set thePadding optionsparameter toConstant.

指定一个标量值来垫的形象.

Dependencies

To enable this port:

  • Set theOutput sizeparameter toSame as input port I.

  • Set thePadding optionsparameter toConstant.

  • Set thePad value sourceparameter toSpecify via dialog.

Block Characteristics

Data Types

Boolean|double|fixed point|integer|single

Multidimensional Signals

no

Variable-Size Signals

yes

References

[1] Gonzalez, Rafael C., and Richard E. Woods.Digital Image Processing. 2nd ed.Upper Saddle River, N.J: Prentice Hall, 2002.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

之前介绍过的R2006a

See Also

Blocks

Functions