Median Filter - Perform 2-D median filtering

Library

Filtering / Analysis & Enhancement

Description

The Median Filter block replaces the central value of an M-by-N neighborhood with its median value. If the neighborhood has a center element, the block places the median value there, as illustrated in the following figure.

If the neighborhood does not have an exact center, the block has a bias toward the upper-left corner and places the median value there, as illustrated in the following figure.

The block pads the edge of the input image so, pixels within [M/2 N/2] of the edges may appear distorted. Because the median value is less sensitive than the mean to extreme values, the Median Filter block can remove salt and pepper noise from an image without significantly reducing the sharpness of the image.

PortInput/OutputSupported Data TypesComplex Values Supported

I

Matrix of intensity values

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • Boolean

  • 8-, 16-, 32-bit signed integer

  • 8-, 16-, 32-bit unsigned integer

No

Val

Scalar value that represents the constant pad value

Same as I port

No

Output

Matrix of intensity values

Same as I port

No

If the data type of the input signal is floating point, the output has the same data type. The data types of the signals input to the I and Val ports must be the same.

Use the Neighborhood size parameter to specify the size of the neighborhood over which the block computes the median. You can enter a scalar value that represents the number of rows and columns in a square matrix or a vector that represents the number of rows and columns in a rectangular matrix.

Use the Output size parameter to specify the size of the output matrix. If you select Same as input port I, the block outputs an intensity image that is the same size as the image input to the I port. If you select Valid, the block only computes the median where the neighborhood fits entirely within the input image, so no padding is required. The dimensions of the output image are

output rows = input rows - neighborhood rows + 1
output columns = input columns - neighborhood columns + 1

If, for the Output size parameter, you choose Same as input port I, the Padding options parameter appear in the dialog box. Use the Padding options parameter to specify how to pad the boundary of your input matrix. To pad your matrix with a constant value, select Constant. To pad your input matrix by repeating its border values, select Replicate. To pad your input matrix with its mirror image, select Symmetric. To pad your input matrix using a circular repetition of its elements, select Circular. For more information on padding, see the Image Pad block reference page.

If, for the Padding options parameter, you select Constant, the Pad value source parameter appears in the dialog box. If you select Specify via dialog, the Pad value parameter appears in the dialog box. Use this parameter to enter the constant value with which to pad your matrix. If, for the Pad value source parameter, you select Input port, the Val port appears on the block. Use this port to specify the constant value with which to pad your matrix.

Fixed-Point Data Types

The information in this section is applicable only when the dimensions of the neighborhood are even.

For fixed-point inputs, you can specify accumulator, product output, and output data types as discussed in Dialog Box. Not all these fixed-point parameters are applicable for all types of fixed-point inputs. The following table shows when each kind of data type and scaling is used.

Output Data Type

Accumulator Data Type

Product Output Data Type

Even M

X

X

Odd M

X

Odd M and complex

X

X

X

Even M and complex

X

X

X

The accumulator and output data types and scalings are used for fixed-point signals when M is even. The result of the sum performed while calculating the average of the two central rows of the input matrix is stored in the accumulator data type and scaling. The total result of the average is then put into the output data type and scaling.

The accumulator and product output parameters are used for complex fixed-point inputs. The sum of the squares of the real and imaginary parts of such an input are formed before the input elements are sorted. The results of the squares of the real and imaginary parts are placed into the product output data type and scaling. The result of the sum of the squares is placed into the accumulator data type and scaling.

For fixed-point inputs that are both complex and have even M, the data types are used in all of the ways described. Therefore, in such cases the accumulator type is used in two different ways.

Dialog Box

The Main pane of the Median Filter dialog box appears as shown in the following figure.

Neighborhood size

Specify the size of the neighborhood over which the block computes the median. You can enter a scalar value that represents the number of rows and columns in a square matrix or a vector that represents the number of rows and columns in a rectangular matrix.

Output size

This parameter controls the size of the output. If you choose Same as input port I, the output has the same dimensions as the input to port I. If you choose Valid, output rows = input rows - neighborhood rows + 1 and output columns = input columns - neighborhood columns + 1.

Padding options

Specify how to pad the boundary of your input matrix. Select Constant to pad your matrix with a constant value. Select Replicate to pad your input matrix by repeating its border values. Select Symmetric to pad your input matrix with its mirror image. Select Circular to pad your input matrix using a circular repetition of its elements. This parameter is visible if, for the Output size parameter, you select Same as input port I.

Pad value source

Use this parameter to specify how to define your constant boundary value. Select Specify via dialog to enter your value in the block parameters dialog box. Select Input port to specify your constant value using the Val port. This parameter is visible if, for the Padding options parameter, you select Constant.

Pad value

Enter the constant value with which to pad your matrix. This parameter is visible if, for the Pad value source parameter, you select Specify via dialog. Tunable.

The Fixed-point pane of the Median Filter dialog box appears as follows. The parameters on this dialog box are only visible when the dimensions of the neighborhood are even.

Rounding mode

Select the rounding mode for fixed-point operations.

Overflow mode

Select the overflow mode for fixed-point operations.

Product output

Use this parameter to specify how to designate the product output word and fraction lengths:

Accumulator

Use this parameter to specify the accumulator word and fraction lengths resulting from a complex-complex multiplication in the block:

Output

Choose how to specify the output word length and fraction length:

Lock scaling against changes by the autoscaling tool

Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling tool in the Fixed-Point Tool. For more information, see fxptdlg, a reference page on the Fixed-Point Tool in the Simulink documentation.

References

[1] Gonzales, Rafael C. and Richard E. Woods. Digital Image Processing. 2nd ed. Englewood Cliffs, NJ: Prentice-Hall, 2002.

See Also

2-D Convolution

Video and Image Processing Blockset software

2-D FIR Filter

Video and Image Processing Blockset software

medfilt2

Image Processing Toolbox software

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS