RegionsToMask Method

NI Vision for Visual Basic

RegionsToMask Method

Syntax

CWIMAQVision.RegionsToMask DestImage, Regions [, ModelImage] [, FillValue = 255]

Return Type

Long

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

Purpose

Transforms a collection of region objects into a mask image.

Remarks

DestImage must be a U8 image.

You can use this method in two ways. The simplest technique is to supply the ModelImage parameter. In this case you can use the source image, in which the regions were drawn, as a template for the final destination image by supplying ModelImage. The output image automatically acquires the size of the image and location of the regions as found in the original source image.

However, you do not have to supply the ModelImage parameter. In this case the regions requires an offset that is determined automatically from the upper-left corner of the bounding rectangle described by the regions. These offset values are automatically set to the image mask.

This method operates on all region objects whose Active property is True.

Parameters

DestImage As CWIMAQImage

The resulting mask image.

Regions As CWIMAQRegions

The regions collection to transform.

ModelImage As Variant

[Optional] Serves as a template for the destination image where the mask is placed. ModelImage can be any image type that NI Vision supports. DestImage takes the characteristics of ModelImage (size and location of regions) when ModelImage is supplied. However, the ModelImage parameter is optional. When no ModelImage is supplied, the size of the image mask generated is limited to the bounding rectangle of the regions, which reduces the amount of memory used. The offset of the image mask generated is set to reflect the real position of the regions.

FillValue As Variant

[Optional] The pixel value of the mask. All pixels inside the region of interest take this value.

This parameter has a default value of 255.

Example

Private Sub Run_Click()
    Dim i As New CWIMAQImage
    
    ' Convert the regions selected on Viewer1 into a mask and
    ' store the result in i.
    CWIMAQVision1.RegionsToMask CWIMAQViewer1.Image, _
                                CWIMAQViewer1.Regions
    
    ' Convert the regions selected on Viewer1 into a mask using
    ' the image in Viewer1 as a model and store the resulting
    ' mask image in the image in Viewer2.
    CWIMAQVision1.RegionsToMask CWIMAQViewer2.Image, _
                                CWIMAQViewer1.Regions, _
                                CWIMAQViewer1.Image
End Sub

See Also

MaskToRegions