CODE to SELECT the OBJECTS in a LEARNING CLASSIFIER CLASS . . .
All --
The IMAGES below illustrate my problem but here is the description.
I have an image that has multiple types of objects within it. In this example they are CIRCLES, SQUARES, PARALLELOGRAMS, and TRIANGLES. I can find the objects and classify them using the LEARNING CLASSIFIER. This is illustrated in the FIRST IMAGE below.
I would then like to be able to SELECT all of the objects in one of the classes and then work with just that set of objects. That is illustrated in the SECOND IMAGE below where I have manually worked with the DATA TABLE to select the SQUARES.
Via the RECORD MACRO I got
Public Function NewMacro() As SimpleScript NewMacro = New SimpleScript Dim doc1 With Application.DocumentCommands.Active(NewMacro) .Run(doc1) End With With Measure.MeasurementsCommands.ShowClass(NewMacro) .Action = McMeasurements.enumShowMeasFlags.smfShowAll .FeatureClass = 2 .Run(doc1) End With With Measure.MeasurementsCommands.SelectAll(NewMacro) .Run(doc1) End With With Measure.MeasurementsCommands.ShowAll(NewMacro) .Action = McMeasurements.enumShowMeasFlags.smfShowAll .FeatureClass = -1 .Run(doc1) End With End Function
when I used the SHOW FEATURE within the MEASUREMENT TABLE and the SELECT ALL within the SELECT MEASUREMENTS TOOL and the SHOW ALL within the HIDE / SHOW OVERLAYS TOOL.
Is there a more efficient way to do something like
SELECT ALL OBJECTS OF CLASS SQUARE
in CODE?
Thanks in advance.
-- Matt
0
Best Answers
-
Hi Matt,
Your code is already efficient, but if you want to use lower level code, here is a sample macro that shows that:Public Sub SelectClass2() 'select all measurement features of class 2 SelectClass(2) End Sub Public Sub SelectClass(ind As Integer) If ThisApplication.ActiveImage Is Nothing Then Exit Sub For Each sf As McMMSubFeature In ThisApplication.ActiveImage.MeasurementsData.SubFeatures sf.Selected=(sf.SfClass=ind)'select the feature of the given class Next End Sub
Yuri0 -
Matt,
Check how it works for your application and let me know if it's not fast enough. These operations involve updates of graphics on the image, which takes time. If you just want to have statistics from certain groups of objects, then there are other ways to get it faster, without changing display.
Like this:Public Sub CalcStatsClass2() 'calculate statistics of class 2 CalcClassStats(2) End Sub Public Sub CalcClassStats(ind As Integer) If ThisApplication.ActiveImage Is Nothing Then Exit Sub Dim vals As New System.Collections.ArrayList For Each sf As McMMSubFeature In ThisApplication.ActiveImage.MeasurementsData.SubFeatures If sf.SfClass=ind Then vals.Add(sf.Value(eMeasures.RgnArea)) End If Next Dim bst As Mediacy.IQL.ObjectManager.BASIC_STATISTICS bst = ThisApplication.GlobalTools.McBasicStatistics(vals.ToArray()) 'get the stats MsgBox(String.Format("Mean area of class {0} = {1}, StDev = {2}, Count = {3}",ind,bst.Mean,bst.StdDev, bst.Count)) End Sub
Yuri0
Answers