MagicWand2 Method

NI Vision for Visual Basic

MagicWand2 Method

Syntax

CWIMAQVision.MagicWand2 SourceImage, DestImage, Origin [, Tolerance = 20.0] [, Connectivity8 = True] [, ReplacementValue = 1]

Return Type

Long

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

Purpose

Creates an image mask by extracting a region surrounding a reference pixel, called the origin, and using a tolerance (+ or -) of intensity variations based on this reference pixel. Using this origin, the method searches for its neighbors with an intensity that equals or falls within the tolerance value of the point of reference. The resulting image is binary.

Remarks

Use this method with U8, I16, and SGL images.

DestImage must be a U8 image. If SourceImage and DestImage are the same image, then SourceImage must be a U8 image.

Parameters

SourceImage As CWIMAQImage

The input image.

DestImage As CWIMAQImage

The resulting image.

Origin As CWIMAQPoint

The origin.

Tolerance As Variant

[Optional] Specifies the pixel value tolerance that the method uses to determine whether neighbors of the reference point are part of the particle.

This parameter has a default value of 20.0.

Connectivity8 As Variant

[Optional] Set this parameter to True to use connectivity-8 to determine whether particles are touching. Set this parameter to False to use connectivity-4 to determine whether particles are touching. For more information about connectivity, refer to the NI Vision Concepts Manual.

This parameter has a default value of True.

ReplacementValue As Variant

[Optional] The value to which the method sets pixels in the selected particle. The method sets pixels outside the particle to 0.

This parameter has a default value of 1.

Example

Private Sub CWIMAQViewer1_RegionsChanged(Count As Variant)
    If Count >= 1 Then
        If CWIMAQViewer1.Regions(1).Shape = cwimaqRegionPoint Then
            CWIMAQVision1.MagicWand2 CWIMAQViewer1.Image, CWIMAQViewer2.Image, CWIMAQViewer1.Regions(1), , , 255
        End If
    End If
End Sub

Magic Wand Example