Click or drag to resize

IMcDisplaySetMaskAlignLeftTop Method

Adjusts the alignment between the masking image and the displayed image.

Namespace:  MediaCy.IQL.Display.Viewer
Assembly:  MediaCy.IQL.Display.Viewer (in MediaCy.IQL.Display.Viewer.dll) Version: 10.0.6912.0
Syntax
VB
Sub SetMaskAlignLeftTop ( 
	lLeft As Integer,
	lTop As Integer
)

Parameters

lLeft
Type: SystemInt32
The X coordinate.
lTop
Type: SystemInt32
The Y coordinate.
Remarks
The masking image may be vertically or horizontally shifted with respect to the displayed image. The parameters represent the X,Y pixel coordinate within the display image where the MaskingImage pixel 0,0 is placed. The parameters may be negative.
Examples
VB
'This is DisplayMaskingSamples.bas
'
'These samples illustrate use of the McDisplay.MaskingImage

Option Explicit

'Note: the Nesting.jpg example image is a good one for most of these examples
Private Function uLoadExampleImage(Optional strImage As String = "Nesting.jpg") As Boolean
    If MsgBox("Open example image?", vbYesNo) = vbYes Then
        Images.Open Path + "Images\" + strImage
    End If 'user wants to open an example image
    'Else leave the ActiveImage alone
    If ActiveImage Is Nothing Then
        MsgBox "There is no ActiveImage, so the example cannot run."
    End If 'don't have image
    uLoadExampleImage = ActiveImage Is Nothing
End Function 'uLoadExampleImage

Private Function uDetectRegions(Optional bNeedHoles As Boolean = True)
    With ActiveImage.RegionFeatures
        .Threshold.Execute 'get some regions
        If .Count = 0 Then
            MsgBox "This image's AOI has no regions.  Pick an image AOI with bright blobs that have holes in them."
            uDetectRegions = True 'no regions
            Exit Function
        End If 'no regions
        If bNeedHoles And (.Holes.Count = 0) Then
            MsgBox "This image's regions have no holes.  Pick an image with bright regions that have holes in them."
            uDetectRegions = True 'no regions
            Exit Function
        End If 'no needed holes
    End With 'ActiveImage.RegionFeatures
    uDetectRegions = False 'found regions
End Function 'uDetectRegions

'Show regions as a colored mask (with holes) overlying the regions
Public Sub ShowYellowRegions()
    If uLoadExampleImage Then Exit Sub
    If uDetectRegions() Then Exit Sub
    With ActiveImage.RegionFeatures
        'Create a mask image from the McRegions
        Dim maskImage As McImage
        Set maskImage = .CreateFeatureMask(mcfmfReturnMaskImage) 'not visible
        With ActiveWindow.View.Display 'the ActiveWindow is still the ActiveImage
            .MaskingImage = maskImage
            .MaskingLUT = &HFFFF&   'yellow
            MsgBox "The image shows the mask in Yellow" + vbCrLf + _
                "When you press OK, the mask will disappear."
            .MaskingImage = Nothing
        End With
    End With 'ActiveImage.RegionFeatures
End Sub 'ShowYellowRegions

'Show an elliptical portion of regions as a colored mask (with holes) overlying the regions
Public Sub ShowPartOfYellowRegions()
    If uLoadExampleImage Then Exit Sub
    If uDetectRegions() Then Exit Sub
    With ActiveImage.RegionFeatures
        'Create a mask image from the McRegions
        Dim maskImage As McImage
        Set maskImage = .CreateFeatureMask(mcfmfReturnMaskImage) 'not visible
        maskImage.Aoi.SetEllipse -1, 200, 200, 300, 200
        With ActiveWindow.View.Display 'the ActiveWindow is still the ActiveImage
            .MaskingImage = maskImage
            .MaskingLUT = &HFFFF&   'yellow
            MsgBox "The image shows an elliptical portion of the mask in Yellow" + vbCrLf + _
                "When you press OK, the mask will disappear."
            .MaskingImage = Nothing
        End With
    End With 'ActiveImage.RegionFeatures
End Sub 'ShowPartOfYellowRegions

'Show regions under the AOI only as a colored mask (with holes) overlying the regions
Public Sub ShowYellowAoiRegions()
    If uLoadExampleImage Then Exit Sub
    ActiveImage.Aoi.SetBox -1, 20, 40, 400, 360
    If uDetectRegions() Then Exit Sub
    With ActiveImage.RegionFeatures
        'Create a mask image from the McRegions under the AOI only
        Dim maskImage As McImage
        Set maskImage = .CreateFeatureMask(mcfmfReturnMaskImage + mcfmfUseAoiBoundsAsDefault) 'not visible
        With ActiveWindow.View.Display 'the ActiveWindow is still the ActiveImage
            .MaskingImage = maskImage
            .MaskingLUT = &HFFFF&   'yellow
                'Align the mask covering the AOI with the AOI
            Dim rectAoi As SINGLERECT
            rectAoi = .ImageToDisplay.Aoi.BoundingRect
            .SetMaskAlignLeftTop rectAoi.Left, rectAoi.Top
            MsgBox "The image shows a mask over the AOI only in Yellow" + vbCrLf + _
                "When you press OK, the mask will disappear."
            .MaskingImage = Nothing
        End With
    End With 'ActiveImage.RegionFeatures
End Sub 'ShowYellowAoiRegions

'Label the larger connected regions under the AOI with a pseudo coloring
Public Sub LabelBigAoiRegions()
    Windows.CloseAll 'start with all windows closed for this one
    If uLoadExampleImage("BoneBig.jpg") Then Exit Sub
    ActiveImage.Aoi.SetBox -1, 20, 40, 400, 360
    If uDetectRegions(False) Then Exit Sub
    With ActiveImage.RegionFeatures
        'First select and keep only the largest 1/2 of the regions
        Dim dCutOffArea As Double
        dCutOffArea = .mRgnArea.Mean / 2
        Dim selSmallAreas As Variant
        selSmallAreas = McOpLT(.mRgnArea.ValueMcObject, dCutOffArea)
        .RemoveFeature selSmallAreas

        'Create a mask image from the McRegions under the AOI only
        Dim maskImage As McImage
        Set maskImage = .CreateFeatureMask(mcfmfReturn16BitLabeledImage + mcfmfUseAoiBoundsAsDefault)
' You don't really need 16-bit labels for display purposes, so the following would look OK and
' use fewer system resources.
'        Set maskImage = .CreateFeatureMask(mcfmfReturn8BitLabeledImage + mcfmfUseAoiBoundsAsDefault)
        With ActiveWindow.View.Display 'the ActiveWindow is still the ActiveImage
            .MaskingImage = maskImage
                'Show all non-zero mask values (these are the labeled pixels)
            .SetMaskingRange 1, maskImage.RangeMax
                'Align the mask covering the AOI with the AOI
            Dim rectAoi As SINGLERECT
            rectAoi = .ImageToDisplay.Aoi.BoundingRect
            .SetMaskAlignLeftTop rectAoi.Left, rectAoi.Top
                'Create a Label pseudo color (different colors for adjacent values)
            Dim psForLabel As New McPseudoColor
            psForLabel.Size = maskImage.RangeMax + 1
            psForLabel.IntensityRange = Array(1, maskImage.RangeMax) 'black pixels are not labeled
            psForLabel.ColorSpectrum = mccsBlueRedLabels
            psForLabel.Visible = True
            .MaskingLUT = psForLabel 'Assign psuedocolor masking LUT
            MsgBox "The image shows larger regions in the AOI, labeled with a pseudocolor." + vbCrLf + _
                "When you press OK, the mask will disappear."
            .MaskingImage = Nothing
        End With
    End With 'ActiveImage.RegionFeatures
End Sub 'LabelBigAoiRegions
See Also