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

bSuccess = CImage:FiltMedian( cols, rows )

bSuccess = CImage:FiltMedian( cols, rows, CRect )

where

    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.

    bSuccess is the returned success code. On success it is true, otherwise 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.

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 = NewRect(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

FiltRect

FiltRank

CImage class