Parent objects
thank you Yuri,
your answer is clear but I need to get the values inside my APP in order to be processed locally.
Is there any possibility to read out from image measurements the required data?
ciao
Maurizio
your answer is clear but I need to get the values inside my APP in order to be processed locally.
Is there any possibility to read out from image measurements the required data?
ciao
Maurizio
0
Best Answer
-
Hi Maurizio,
You can read the measurements in a loop and sort them by eMeasures.AnyParentName and eMeasures.AnyClassName.
Here is the macro that does it:'class to collect stats Public Class ClassStats Public dict As New System.Collections.Generic.Dictionary(Of String,Integer) Public Sub New(clName As String) dict.Add(clName,1) End Sub End Class Public Module Module1 'Report parent-class statistics Public Sub ReportParentStats Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub Dim md As McMMData=im.MeasurementsData Dim parents As New System.Collections.Generic.Dictionary(Of String,ClassStats) For Each sf As McMMSubFeature In md.SubFeatures 'get parent name Dim par As String=sf.Value(eMeasures.AnyParentName)'get parent If par="" Then Continue For'ignore objects withot parents (parents themselves) Dim clName As String=sf.Value(eMeasures.AnyClassName)'get class If Not parents.ContainsKey(par) Then 'create new entry parents.Add(par,New ClassStats(clName)) Else 'add to existing Dim cls As ClassStats=parents(par) If cls.dict.ContainsKey(clName) Then cls.dict(clName)=cls.dict(clName)+1 Else cls.dict.Add(clName,1) End If End If Next 'report objects of each class ThisApplication.Output.Show For Each kvKey As String In parents.Keys ThisApplication.Output.PrintMessage(String.Format("Number of objects in parent {0}",kvKey)) Dim parVal As ClassStats=parents(kvKey) For Each kvCl As System.Collections.Generic.KeyValuePair(Of String,Integer) In parVal.dict ThisApplication.Output.PrintMessage(String.Format("{0} = {1}",kvCl.Key,kvCl.Value)) Next Next End Sub End Module
The output looks like this:Number of objects in parent P1Class 2 = 2Class 3 = 3Number of objects in parent P2Class 2 = 3Class 3 = 6
I've also attached the project.
Regards,
Yuri0
Answers
-
It looks like I forgot to attach the project. Here it is.
Also, I've adjusted project for 9.1.4 (Sub New couldn't have parameters)Imports MediaCy.Addins.Measurements 'class to collect stats Class ClassStats Public dict As New System.Collections.Generic.Dictionary(Of String,Integer) End Class Public Module Module1 'Report parent-class statistics Public Sub ReportParentStats Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub Dim md As McMMData=im.MeasurementsData Dim parents As New System.Collections.Generic.Dictionary(Of String,ClassStats) For Each sf As McMMSubFeature In md.SubFeatures 'get parent name Dim par As String=sf.Value(eMeasures.AnyParentName)'get parent If par="" Then Continue For'ignore objects withot parents (parents themselve) Dim clName As String=sf.Value(eMeasures.AnyClassName)'get class If Not parents.ContainsKey(par) Then 'create new entry Dim cl As New ClassStats cl.dict.Add(clName,1) parents.Add(par,cl) Else 'add to existing Dim cls As ClassStats=parents(par) If cls.dict.ContainsKey(clName) Then cls.dict(clName)=cls.dict(clName)+1 Else cls.dict.Add(clName,1) End If End If Next 'report objects of each class ThisApplication.Output.Show For Each kvKey As String In parents.Keys ThisApplication.Output.PrintMessage(String.Format("Number of objects in parent {0}",kvKey)) Dim parVal As ClassStats=parents(kvKey) For Each kvCl As System.Collections.Generic.KeyValuePair(Of String,Integer) In parVal.dict ThisApplication.Output.PrintMessage(String.Format("{0} = {1}",kvCl.Key,kvCl.Value)) Next Next End Sub End Module
Yuri0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions