2D median filtering
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.
|Code Generation Support|
|Supports MATLAB® Function block: Yes|
|System Objects in MATLAB Code Generation.|
|Code Generation Support, Usage Notes, and Limitations.|
Size of neighborhood to compute the median
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].
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.
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.
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.
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.
|clone||Create 2D median filter with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs from step method|
|isLocked||Locked status for input attributes and non-tunable properties|
|release||Allow property value and input characteristics changes|
|step||Perform median filtering on input image|
Read the image and add noise.
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');
This object implements the algorithm, inputs, and outputs described on the Median Filter block reference page. The object properties correspond to the block parameters.