Click or drag to resize

IMcPointsCleanUpBordersAndNoise Method

Removes small features and/or those that touch selected borders of the Image or the borders of a specified McRegions instance.

Namespace:  MediaCy.IQL.Features
Assembly:  MediaCy.IQL.Features (in MediaCy.IQL.Features.dll) Version: 10.0.6912.0
Syntax
VB
Sub CleanUpBordersAndNoise ( 
	<OptionalAttribute> McRegionsBorder As Object,
	Optional BorderFlags As mcRegionBorders = mcRegionBorders.mcrbAllBorders,
	Optional MinSize As Integer = 0
)

Parameters

McRegionsBorder (Optional)
Type: SystemObject
If given, this is a McRegions instance that holds the region features borders that are to be tested against. This argument is normally supplied and will usually be the AOI of the parent image (see Example). If not given, then the border is tested against the borders of the parent image (failure to have a parent image is an error in this case). Should the McRegions holding the borders have no features, then the borders of its parent image are used as the borders to test against.
BorderFlags (Optional)
Type: MediaCy.IQL.FeaturesmcRegionBorders
Flags, which can be OR'ed together to denote which borders to test. The default value of mcrbAllBorders tests against all borders, and mcrbNoBorder skips the border test (testing only for MinSize). For irregular or multiple McRegionsBorder features's (ones with a Type(-1) property other than mcftBox), then a McRegionsBorder border is a boundary pixel of any AOI sub-region. Some border pixels may be on two (or more directions). For example, the left, top corner point of a rectangular (mcftBox) McRegionsBorder will be used for both the mcrbWest and mcrbNorth tests. Features that fall partially or completely outside of any McRegionsBorder may be aggressively removed to ensure that all features outside of the selected borders are gone. For McPoints, only points outside of or exactly on a McRegionsBorder boundary will be removed, even if the blob from which the point was detected did touch a boundary (see Sub DetectNonTouchingCentroids in the samples for a way to avoid marking points on blobs that touch AOI boundaries).
MinSize (Optional)
Type: SystemInt32
If given, a minimum size for the features to be kept. In the case of McRegions, this is the mininum area of the region in units of square pixels. In the case of McLines, this is the minimum length of the line or polyline, in units of pixels. In the case of McPoints, this is the minimum area of the blob from which the point feature was created from bit mask data via the SetFromMask method or via the Threshold property. Point features placed directly by calling SetFeaturePoints are assumed to be one pixel in size.

Implements

IMcFeaturesCleanUpBordersAndNoise(Object, mcRegionBorders, Int32)
Remarks
Any feature that touches or is outside of selected parent image borders (or selected borders of a specified McRegions instance: usually the AOI) will be removed. This is useful for getting rid of features that were possibly clipped by the image border or by an AOI when they are created by the Threshold property (an instance of McThreshold, which can segment image data into foreground and background pixels based on image luminance or color). In addition, if the MinSize argument is non-zero, then it describes a minimum size for features to be preserved. The test is performed on the bit mask representation of features, so the resolution of the test is at the pixel level.
Examples
VB
'**** CleanUpBordersAndNoiseSamples.bas ****

Option Explicit

'Note: the BoneBig.jpg example image is a good one for these examples
Private Function uLoadExampleImage(Optional strImage As String = "BoneBig.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
    uLoadExampleImage = ActiveImage Is Nothing
End Function 'uLoadExampleImage


'Utility sub to remove any existing features
Public Sub ResetAllStandardFeatures()
    If ActiveImage Is Nothing Then Exit Sub
    With ActiveImage
        .PointFeatures.Reset
        .LineFeatures.Reset
        .RegionFeatures.Reset
    End With 'ActiveImage
End Sub 'ResetAllStandardFeatures

'Remove region features touching the AOI and ones with area smaller than 25 square pixels
Public Sub RemoveSmallAndTouchingRegions()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.SetBox -1, 100, 100, 250, 250
        .RegionFeatures.Threshold.Execute
        .RegionFeatures.CleanUpBordersAndNoise .Aoi, mcrbAllBorders, 25
    End With 'ActiveImage
End Sub 'RemoveSmallAndTouchingRegions

'Detect blob centers and remove points marking small blobs (< 100 square pixels)
Public Sub DetectNonSmallPoints()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.SetBox -1, 100, 100, 250, 250
        .PointFeatures.SetFromMaskMethod = mcsfmmPointsCentroid
        .PointFeatures.Threshold.Execute 'mark centers of blobs
        .PointFeatures.CleanUpBordersAndNoise .Aoi, mcrbNoBorder, 100
    End With 'ActiveImage.
End Sub 'DetectNonSmallPoints

'Another way to do the above that does not mark any blob touching an AOI boundary
Public Sub DetectNonTouchingCentroids()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.SetBox -1, 100, 100, 250, 250
        Dim mcregionsT As McRegions
        Set mcregionsT = CreateOperator("McRegions", ActiveImage)
        mcregionsT.Threshold.Execute 'find blobs
            'get rid of touching and small blobs
        mcregionsT.CleanUpBordersAndNoise .Aoi, mcrbAllBorders, 100
            'now set PointFeatures from the region centroids
        .PointFeatures.CopyFrom mcregionsT.mpRgnCentroidAsPoint.value
        Set mcregionsT = Nothing 'all done with our temp McRegions
    End With 'ActiveImage.
End Sub 'DetectNonTouchingCentroids

'Remove region features touching each border in turn
Public Sub RemoveTouchingRegionsInTurn()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.SetBox 0, 25, 25, 200, 200
        .Aoi.SetEllipse 1, 250, 270, 250, 100
        .Aoi.SetBox 2, 250, 100, 350, 200
        .RegionFeatures.Threshold.Execute
        MsgBox "OK to remove North regions"
        .RegionFeatures.CleanUpBordersAndNoise .Aoi, mcrbNorth
        MsgBox "OK to remove South regions"
        .RegionFeatures.CleanUpBordersAndNoise .Aoi, mcrbSouth
        MsgBox "OK to remove West regions"
        .RegionFeatures.CleanUpBordersAndNoise .Aoi, mcrbWest
        MsgBox "OK to remove East regions"
        .RegionFeatures.CleanUpBordersAndNoise .Aoi, mcrbEast
        MsgBox "OK to clear all regions"
        .RegionFeatures.Reset
    End With 'ActiveImage
End Sub 'RemoveTouchingRegionsInTurn

'Detect lines and remove ones shorter than 30 pixels
Public Sub DetectNonShortLines()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.Reset 'whole image
        .LineFeatures.SetFromMaskMethod = mcsfmmLinesMajorAxisAlignedAvg
        .LineFeatures.Threshold.Execute 'draw lines across blobs
        .LineFeatures.CleanUpBordersAndNoise .Aoi, mcrbNoBorder, 30
    End With 'ActiveImage.
End Sub 'DetectNonShortLines

'Another way to do the above that does not draw a line on any
'blob touching an AOI boundary.  Lines shorter than 20 pixels are removed.
Public Sub DetectNonTouchingNonShortLines()
    ResetAllStandardFeatures 'remove any existing features
    If uLoadExampleImage Then Exit Sub
    With ActiveImage
        .Aoi.SetBox -1, 20, 20, 300, 300
        Dim mcregionsT As McRegions
        Set mcregionsT = CreateOperator("McRegions", ActiveImage)
        mcregionsT.Threshold.Execute 'find blobs
            'get rid of very small and touching blobs
        mcregionsT.CleanUpBordersAndNoise .Aoi, mcrbAllBorders, 20
            'now set LineFeatures from the cleaned regions' BitMask
        Dim regionsBitMask As McBitMask
        Set regionsBitMask = mcregionsT.CreateFeatureMask(mcfmfReturnMcBitMask)
        Set mcregionsT = Nothing 'all done with our temp McRegions
        .LineFeatures.SetFromMask regionsBitMask, mcsfmmLinesMajorAxisAlignedAvg
            'finally, we get rid of short lines
        .LineFeatures.CleanUpBordersAndNoise .Aoi, mcrbNoBorder, 20
    End With 'ActiveImage.
End Sub 'DetectNonTouchingNonShortLines
See Also