Click or drag to resize

IMcDisplayMaskingImage Property

A McImage used for masking.

Namespace:  MediaCy.IQL.Display.Viewer
Assembly:  MediaCy.IQL.Display.Viewer (in MediaCy.IQL.Display.Viewer.dll) Version: 10.0.6912.0
Syntax
VB
Property MaskingImage As McImage
	Get
	Set

Property Value

Type: McImage
Remarks
The MaskingImage is an optional image that allows for a special form of overlay drawing. Generally this is used for quickly showing a solid graphic overlay, such as ones viewed during interactive threshold setting processes. Only the portion of the MaskingImage that underlies the AOI is used for masking. Furthermore, MaskingImage pixels with values outside of the range of values given by the SetMaskingRange method are not masked (transparent). The MaskingImage must be either an 8-bit, 12-bit or 16-bit monochrome, RGB or BGR image. That is, the MaskingImage McImage.Type must be McImageType.Interpretation mciMonochrome, mciRGB or mciBGR, McImageType.PixelDataType mcpdtInteger, and McImageType.BitsPerChannel mcbpc8Bits, mcbpc12Bits or mcbpc16Bits. These correspond to mcImageQuickTypes of mciqtGray, mciqtRGB, mciqtGray12, mciqtRGB36, mciqtGray16 and mciqtRGB48 respectively. The most common source for a MaskingImage will be the McFeatures.CreateFeatureMask method, usually called on a McRegions type of McFeatures. The CreateFeatureMask method can return either a mciqtGray or mciqtGray16 mask or feature-labeled McImage. No psuedocoloring will be done unless the MaskingLUT property is set. The image does not need to be the same size as the ImageToDisplay and its alignment can set with the SetMaskAlignLeftTop method. Unless the MaskingFrame property is assigned to, the McImage.ActiveFrame will be used for masking.
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