ShapeMatch Method

NI Vision for Visual Basic

ShapeMatch Method

Syntax

CWIMAQVision.ShapeMatch SourceImage, PatternImage, DestImage, ShapeReport [, ScaleInvariance = True] [, Tolerance = .03] [, Connectivity8 = True]

Return Type

Long

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

Purpose

Finds objects in an image whose shape matches the shape of the object specified by a template.

Remarks

SourceImage and PatternImage must be U8 binary images that contain only pixel values of 0 or 1.

The matching process is invariant to rotation. You can set the match process to be invariant to the scale of the objects. This method labels each object in the image with a unique identification number before performing the match operation.

Parameters

SourceImage As CWIMAQImage

A U8 or I16 binary image that contains objects of different shapes.

PatternImage As CWIMAQImage

A U8 binary image that contains the object to match.

DestImage As CWIMAQImage

The resulting image that contains the objects in the source image that match the object in the template image.

ShapeReport As CWIMAQShapeReport

On return, a report containing information about the matched objects.

ScaleInvariance As Variant

[Optional] Set this parameter to True to search for shapes regardless of size. Set this parameter to False to search for shapes that are ± 10 percent the same size as the template shape.

This parameter has a default value of True.

Tolerance As Variant

[Optional] Specifies the allowable difference between the template shape and similar shapes in the image. The difference is expressed as a value from 0 to 1.

This parameter has a default value of .03.

Connectivity8 As Variant

[Optional] Specifies how the algorithm determines whether an adjacent pixel belongs to the same or to a different particle.

This parameter has a default value of True.

Example

' Match the template shape stored in i in the image in Viewer1.
' Store the result in the image in Viewer2
Private Sub Run_Click()
    Dim i As New CWIMAQImage
    Dim report As New CWIMAQShapeReport
    
    ' Convert the image in Viewer1 into a binary image
    CWIMAQVision1.Threshold CWIMAQViewer1.Image, CWIMAQViewer1.Image, _
                            128, 255
    ' Convert i into a binary image
    CWIMAQVision1.Threshold i, i, 128, 255
    
    ' Perform the ShapeMatch
    CWIMAQVision1.ShapeMatch CWIMAQViewer1.Image, i, _
                             CWIMAQViewer2.Image, report
End Sub