CImage:FiltMedian


The FiltMedian method applies a median filter to the image. This filter may be used for smoothing or for removing impulse noise.

Syntax

bResult = CImage:FiltMedian( cols, rows, CRect=nil )

bullet.gif    cols is the column length of the filter kernel.

bullet.gif    rows is the row length of the filter kernel.

bullet.gif    CRect is the rectangle defining the area to process. If omitted, it defaults to nil and the entire image is processed.

bullet.gif    On success, this method returns true.

bullet.gif    On failure, this method returns false.

Remarks

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.

Example

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:

I = V:GetImage()

-- attach the current displayed image

R = new_rect(100,300,400,800)

-- setup the rectangle to process

I:FiltMedian(3,3,R)

-- apply the filter

V:Update()

-- update the display after the scale

R:delete()

-- done with the CRect

Related Topics

CImage class, FiltRect, FiltRank


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.