IMcRegionsGetOrderedPosition Method |
![]() |
Namespace: MediaCy.IQL.Features
Function GetOrderedPosition ( Optional Ordering As mcPositionOrdering = mcPositionOrdering.mcpoByBoundsMidPoint, <OptionalAttribute> Selector As Object ) As Object
'These samples illustrate various sortings of features based on 'feature properties '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 ActiveImage.Aoi.SetBox -1, 10, 10, 160, 160 ActiveWindow.View.Magnification = 3# 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." Else Output.Show "Output" Output.Clear ActiveImage.RegionFeatures.Reset ActiveImage.LineFeatures.Reset End If uLoadExampleImage = ActiveImage Is Nothing End Function 'uLoadExampleImage 'Show the ordering of region centroids from top-to-bottom, left-to-right Public Sub OrderByPosition() If uLoadExampleImage Then Exit Sub With ActiveImage.RegionFeatures .Threshold.Execute 'get some regions Dim selOrdering() As Long selOrdering = .GetOrderedPosition(mcpoByBoundsMidPoint) Output.PrintMessage "Region mid-point ordering for " & .Count & " regions:" & vbCrLf & _ McToText(selOrdering) End With 'ActiveImage.RegionFeatures End Sub 'OrderByPosition 'Show the ordering of regions by area. The smallest 1/2 of the areas are removed. Public Sub OrderByAreaAndRemoveSmallerOnes() If uLoadExampleImage Then Exit Sub With ActiveImage.RegionFeatures .Threshold.Execute 'get some regions Dim selOrdering() As Long selOrdering = McSort(.mRgnArea) Output.PrintMessage "Region area-size ordering for " & .Count & " regions:" & vbCrLf & _ McToText(selOrdering) 'Now remove the smallest 1/2 of areas If .Count < 2 Then Exit Sub .RemoveFeature McOpSelect(selOrdering, McOpFillIn(0, .Count / 2)) End With 'ActiveImage.RegionFeatures End Sub 'OrderByAreaAndRemoveSmallerOnes 'Show the ordering of lines by the postion of their end-points. Ordering of the 'end points is from top-to-bottom, left-to-right Public Sub OrderByLineEndPoints() If uLoadExampleImage Then Exit Sub With ActiveImage.LineFeatures .SetFromMaskMethod = mcsfmmLinesLongestStraight .Threshold.Execute 'get lines across blobs 'Since Points are x and y, we need to create a number that is 'ordered by y and then x If .Count = 0 Then Exit Sub Dim dYthenX() As Double dYthenX = McOpAdd(McOpMul(McOpCast(.mLnEndY, "REAL"), 30000#), .mLnEndX) Dim selOrdering() As Long selOrdering = McSort(dYthenX) 'Show the ordering on the image, fill SourceData with feature order Dim nL As Long For nL = 0 To .Count - 1 .SourceData(selOrdering(nL)) = nL + 1 Next nL 'and show that as a label .DisplayedObjects.SetLabelText "%d", mcsltDisplaySourceData + mcsltLabelLineend ' + mcgsLabelCenter Output.PrintMessage "Line ordering by EndPt for " & .Count & " lines:" & vbCrLf & _ McToText(selOrdering) End With 'ActiveImage.LineFeatures End Sub 'OrderByAreaAndRemoveSmallerOnes