CImage:FiltMedian
The FiltMedian method applies a median filter to the image. This filter may be used for smoothing or for removing impulse noise.
bResult = CImage:FiltMedian( cols, rows, CRect=nil ) |
cols is the column length of the filter kernel.
rows is the row length of the filter kernel.
CRect is the rectangle defining the area to process. If omitted, it defaults to nil and the entire image is processed.
On success, this method returns true.
On failure, this method returns false.
This method applies a rectangular median filter to the image. The median is a nonlinear selection operation that replaces each pixel with the middle value from among its neighbors. This is nonlinear because the replacement value cannot be computed by applying linear operations (addition and multiplication) to other pixel values.
This filter makes an excellent tool for removing impulse noise such as hot pixels, although doing so adds a small amount of smoothing to the image. The defect to be removed must be smaller than 1/2 the filter kernel dimension. For example, a 3x3 filter will remove single point defects.
Used as a smoothing filter, the median is effective but very slow, although it is superior at preserving sharp edges in comparison with FiltRect or similar methods. However, with coarsely quantized or low signal to noise ratio integer type images, a median filter can produce Mach banding in the output image.
Suppose an image is displayed in a CImageView named V. The following script removes point defects from the [100:300, 400:800] pixel region using a 3x3 median filter:
|
-- attach the current displayed image |
|
-- setup the rectangle to process |
|
-- apply the filter |
|
-- update the display after the scale |
|
-- done with the CRect |
CImage class, FiltRect, FiltRank
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics,
Inc. All Rights Reserved.