UserLookup Method

NI Vision for Visual Basic

UserLookup Method

Syntax

CWIMAQVision.UserLookup SourceImage, DestImage, LookupTable [, MaskImage]

Return Type

Long

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

Purpose

Performs a user-defined lookup table transformation by remapping the pixel values in an image.

Remarks

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

Parameters

SourceImage As CWIMAQImage

The image to process.

DestImage As CWIMAQImage

The resulting image.

LookupTable As Variant

The lookup table. For 8-bit images, the lookup table must contain 256 elements. The method replaces each pixel value v with LookupTable(v). For 16-bit images, the lookup table must contain 65,536 elements. The method replaces each non-negative pixel value v with LookupTable(v) and replaces each negative pixel value v with LookupTable(65536+v).

MaskImage As Variant

[Optional] A CWIMAQImage object that indicates the region in the image to use for the user lookup. 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 transform the entire image.

Example

Private Sub Run_Click()
    Dim LookupTable As Variant
    Dim i As New CWIMAQImage
    Dim maskImage As New CWIMAQImage
    
    ' Create a lookup table
    Dim a(0 To 255) As Long
    Dim i1
    For i1 = 0 To 255
        a(i1) = Abs(128 - i1)
    Next
    LookupTable = a

    ' Perform a UserLookup on the entire image in Viewer1.
    ' Store the result in i.
    CWIMAQVision1.UserLookup CWIMAQViewer1.Image, i, LookupTable
    
    ' Perform a UserLookup on the portion of the image
    ' in Viewer1 based on the regions selected on Viewer1.
    ' Do the operation inplace.
    CWIMAQVision1.RegionsToMask maskImage, CWIMAQViewer1.Regions
    CWIMAQVision1.UserLookup CWIMAQViewer1.Image, CWIMAQViewer1.Image, _
                             LookupTable, maskImage
End Sub