IMcLinesCleanUpBordersAndNoise Method |
![]() |
Namespace: MediaCy.IQL.Features
Sub CleanUpBordersAndNoise ( <OptionalAttribute> McRegionsBorder As Object, Optional BorderFlags As mcRegionBorders = mcRegionBorders.mcrbAllBorders, Optional MinSize As Integer = 0 )
'**** 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