Main Content

Median Filter

2-D median filtering

  • Library:
  • Vision HDL Toolbox / Analysis & Enhancement

    Vision HDL Toolbox / Filtering

  • Median Filter block

Description

TheMedian Filterblock replaces each input pixel with the median value of a specified surroundingN-by-Nneighborhood. The median is less sensitive to extreme values than the mean. You can use this block to remove salt-and-pepper noise from an image without significantly reducing the sharpness of the image. You can specify the neighborhood size and padding values for edges of the input image.

Ports

This block uses a streaming pixel interface with a bus for frame control signals. This interface enables the block to operate independently of image size and format. Thepixelports on this block support single pixel streaming or multipixel streaming. Single pixel streaming accepts and returns a single pixel value each clock cycle. Multipixel streaming accepts and returns a vector ofMpixels per clock cycle to support high-frame-rate or high-resolution formats. TheMvalue corresponds to theNumber of pixelsparameter of theFrame To Pixelsblock. Along with the pixel, the block accepts and returns apixelcontrolbus that contains five control signals. The control signals indicate the validity of each pixel and their location in the frame. For multipixel streaming, one set of control signals applies to all pixels in the vector. To convert a frame (pixel matrix) into a serial pixel stream and control signals, use theFrame To Pixelsblock. For a full description of the interface, seeStreaming Pixel Interface.

Input

expand all

This block supports single pixel streaming or multipixel streaming. For single pixel streaming, specify a single input pixel as a scalar intensity value. For multipixel streaming, specify a vector of four or eight pixel intensity values. For details of how to set up your model for multipixel streaming, seeFilter Multipixel Video Streams.

This block does not support multicomponent streaming. To process multicomponent streams, replicate the block for each component. Thepixelcontrolbus for all components is identical, so you can connect a single bus to multiple replicated blocks.

doubleandsingledata types are supported for simulation, but not for HDL code generation.

Data Types:uint|int|fixed point|Boolean|double|single

Thepixelcontrolbus contains five signals. The signals describe the validity of the pixel and its location in the frame. For more information, seePixel Control Bus.

For multipixel streaming, each vector of pixel values has one set of control signals. Because the vector has only onevalidsignal, the pixels in the vector must be either all valid or all invalid. ThehStartandvStartsignals apply to the pixel with the lowest index in the vector. ThehEndandvEndsignals apply to the pixel with the highest index in the vector.

Data Types:bus

Output

expand all

This block supports single pixel streaming or multipixel streaming. When using single pixel streaming, the block returns a single pixel as a scalar intensity value. When using multipixel streaming, the block returns a vector of intensity values. This vector is the same size as the inputpixelvector. For details of how to set up your model for multipixel streaming, seeFilter Multipixel Video Streams.

The output pixel data type is the same as the data type of the input pixels.

doubleandsingledata types are supported for simulation, but not for HDL code generation.

Data Types:uint|int|fixed point|Boolean|double|single

Thepixelcontrolbus contains five signals. The signals describe the validity of the pixel and its location in the frame. For more information, seePixel Control Bus.

For multipixel streaming, each vector of pixel values has one set of control signals. Because the vector has only onevalidsignal, the pixels in the vector must be either all valid or all invalid. ThehStartandvStartsignals apply to the pixel with the lowest index in the vector. ThehEndandvEndsignals apply to the pixel with the highest index in the vector.

Data Types:bus

Parameters

expand all

Select the neighborhood size, in pixels, as3×3,5×5, or7×7.

You cannot use a neighborhood size of7×7when you use multipixel streaming and setPadding methodtoNone.

Select one of these methods for padding the boundary of the input image. For more information about these methods, seeEdge Padding.

  • Constant— Interpret pixels outside the image frame as having a constant value.

  • Replicate— Repeat the value of pixels at the edge of the image.

  • Symmetric— Set the value of the padding pixels to mirror the edge of the image.

  • Reflection——设置填充像素的值反映了round the pixel at the edge of the image.

  • None——排除填充逻辑。块不设置the pixels outside the image frame to any particular value. This option reduces the hardware resources used by the block and the blanking required between frames but affects the accuracy of the output pixels at the edges of the frame. To maintain pixel stream timing, the output frame is the same size as the input frame. However, to avoid using pixels calculated from undefined padding values, mask off theKernelSize/2 pixels around the edge of the frame for downstream operations. For details, seeIncrease Throughput with Padding None.

You cannot use a neighborhood size of7×7when you setPadding methodtoNone.

Specify an integer to pad the boundary of the input image. The block casts this value to the same data type as the input pixel.

Dependencies

To enable this parameter, set thePadding methodparameter toConstant.

Size of line memory buffer, specified as a positive integer. Choose a power of two that accommodates the number of active pixels in a horizontal line. If you specify a value that is not a power of two, the buffer uses the next largest power of two.

The block allocates (N— 1) -by-Line buffer sizememory locations to store the pixels used to compute the median value.Nis the dimension of the square region specified by theNeighborhood sizeparameter.

Tips

  • When you use a block with an internal line buffer inside anEnabled Subsystem(Simulink), the enable signal pattern must maintain the timing of the pixel stream, including the minimum blanking intervals. If the enable pattern corrupts the timing of the pixel stream, you might see partial output frames, corrupted pixel stream control signals, or mismatches between Simulink®and HDL simulation results. You may need to extend the blanking intervals to accommodate for cycles when the enable is low. For more information, seeConfigure Blanking Intervals.

Algorithms

expand all

When you use multipixel streaming, the block uses a single line memory and implements one filter kernel for each of theMinput pixels, in parallel. This increase in hardware resources is a trade off for increasing throughput compared to single-pixel streaming.

Extended Capabilities

Version History

Introduced in R2015a

See Also

(Computer Vision Toolbox)||