MedianFilter Method

NI Vision for Visual Basic

MedianFilter Method

Syntax

CWIMAQVision.MedianFilter SourceImage, DestImage [, XFilterSize = 3] [, YFilterSize = 3] [, MaskImage]

Return Type

Long

On success, this method returns 0. On failure, this method returns a negative number.

Purpose

Filters an image using a nonlinear filter. For each pixel, the algorithm takes the neighborhood specified by the given filter sizes and replaces the pixel with the median value of the neighborhood.

Remarks

This method modifies the source image. If you need the original source image, create a copy of the image using the CWIMAQVision.Copy method before using this method.

Use this method with U8, I16, and SGL images. MaskImage must be a U8 image.

The filter modifies the border of the source image. The connected source image must have been created with a border capable of supporting the size of the convolution matrix. A 3 x 3 matrix must have a minimum border of 1, a 5 x 5 matrix must have a minimum border of 2, and so on. The border size of the destination image is not important.

Parameters

SourceImage As CWIMAQImage

The image to filter.

DestImage As CWIMAQImage

The destination image.

XFilterSize As Variant

[Optional] The size of the horizontal matrix axis. This number must be odd.

This parameter has a default value of 3.

YFilterSize As Variant

[Optional] The size of the vertical matrix axis. This number must be odd.

This parameter has a default value of 3.

MaskImage As Variant

[Optional] A CWIMAQImage object that contains the mask applied to the source image. The mask indicates the region in which the method applies the median filter. The method processes only those pixels in the image whose corresponding pixels in the mask are non-zero. Do not set this parameter if you want to apply the filter to the entire image.

Example

Dim i As New CWIMAQImage
Dim maskImage As New CWIMAQImage

' Apply a median filter to a portion of the image in Viewer1
' defined by regions selected on Viewer1.
' Store the result in i.
CWIMAQVision1.RegionsToMask maskImage, CWIMAQViewer1.regions
CWIMAQVision1.MedianFilter CWIMAQViewer1.Image, i, , , _
                           maskImage