Correlate2 Method

NI Vision for Visual Basic

Correlate2 Method

Syntax

CWIMAQVision.Correlate2 SourceImage, PatternImage, DestImage [, Rectangle]

Return Type

Long

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

Purpose

Computes the normalized cross correlation between the source image and the template image.

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 images. This method is optimized for MMX. However, MMX optimization is valid only when the width of the template image is a multiple of 4.

Correlation is a time-intensive operation. You can reduce the time required to perform a correlation by keeping the template size small and reducing the search area in the source image using a Rectangle.

Parameters

SourceImage As CWIMAQImage

The source image. The correlation modifies the border of the source image. The border must be at least half as large as the larger dimension of the template image.

PatternImage As CWIMAQImage

The template image to correlate against the source.

DestImage As CWIMAQImage

The resulting 8-bit image containing the cross correlation values normalized to lie in the range [0, 255]. A value of 255 indicates a very high correlation and a value of 0 indicates no correlation.

Rectangle As Variant

[Optional] A CWIMAQRectangle variable which defines a rectangular region in the source image that is used for the correlation process. Correlation is applied to the entire image if the rectangle is not specified.

Example

Dim patternImage As New CWIMAQImage
Dim i As New CWIMAQImage
Dim rectangle As New CWIMAQRectangle

' Populate patternImage and rectangle

' Correlate the patternImage with the image in Viewer1
' Store the results in i.
CWIMAQVision1.Correlate2 CWIMAQViewer1.Image, patternImage, _
                        i, rectangle