CODE to get CLASS STATISTICS . . .
2021-03-25-192625
All --
I have an APP which is identifying two CLASSES of objects.
I would like to extract some of the STATS on those two CLASSES.
If I have an image that is generating a DATA TABLE like the one below, is there a way to get to the values directly from DATA TABLE or via the
ThisApplication.ActiveImage.MeasurementsData.SubFeatures
?
I would like something that would allow
Dim MyCenterFeaturesLengthMean = CODE
where MyCenterFeaturesLengthMean would receive the value of 5.13
I can do this by adding the FEATURE LENGTHS to an ARRAY and then doing the STATS on the ARRAY but I would rather reach into the DATA TABLE and get the values that have already been calculated if that is possible.
I have done this before for a single CLASS (below) but I do not know how to do this when there are multiple classes.
Public Sub MeanArea()
'CONNECT WITH THE ACTIVE IMAGE
Dim doc1
With Application.DocumentCommands.Active(Nothing)
.Run(doc1)
End With
'CONNECT WITH THE DATA IN THE IMAGE
Dim My_Data1 As McMMData
With measure.MeasurementsCommands.GetData(Nothing)
.Run(ThisApplication.ActiveDocument, My_Data1)
End With
'CONNECT WITH THE AREA MEASUREMENTS IN THE IMAGE
Dim My_Measure1 As New MeasEntry
My_Measure1.Measurement=eMeasures.RgnArea
'LEARN THE STATISTICS FOR THE OBJECTS IN THE IMAGE
Dim My_Stats1(8) As Double
My_Data1.CalcStatistics(My_Measure1,My_Stats1)
ThisApplication.Output.PrintMessage("Mean Area = " & My_Stats1(0))
ThisApplication.Output.PrintMessage("SD Area = " & My_Stats1(1))
ThisApplication.Output.PrintMessage("Min Area = " & My_Stats1(2))
ThisApplication.Output.PrintMessage("Max Area = " & My_Stats1(3))
End Sub
'CONNECT WITH THE ACTIVE IMAGE
Dim doc1
With Application.DocumentCommands.Active(Nothing)
.Run(doc1)
End With
'CONNECT WITH THE DATA IN THE IMAGE
Dim My_Data1 As McMMData
With measure.MeasurementsCommands.GetData(Nothing)
.Run(ThisApplication.ActiveDocument, My_Data1)
End With
'CONNECT WITH THE AREA MEASUREMENTS IN THE IMAGE
Dim My_Measure1 As New MeasEntry
My_Measure1.Measurement=eMeasures.RgnArea
'LEARN THE STATISTICS FOR THE OBJECTS IN THE IMAGE
Dim My_Stats1(8) As Double
My_Data1.CalcStatistics(My_Measure1,My_Stats1)
ThisApplication.Output.PrintMessage("Mean Area = " & My_Stats1(0))
ThisApplication.Output.PrintMessage("SD Area = " & My_Stats1(1))
ThisApplication.Output.PrintMessage("Min Area = " & My_Stats1(2))
ThisApplication.Output.PrintMessage("Max Area = " & My_Stats1(3))
End Sub
Thanks in advance.
-- Matt
0
Best Answers
-
Hi Matt,
Statistics per class can be easily collected using into "Measurements Class Stats" table of the data collector:
Let me know if it will work for you.
Otherwise the stats should be calculated in a macro from the arrays of values, which requires some code.
Yuri
0 -
Hi Matt,
Yes, your approach is correct, the goal would be to collect values from different classes into different containers and then get statistics of those containers. You could use our class McBasicStatistics or use Linq functions with .NET containers (List in your example).
Regards,
Yuri0
Answers
Dim MyStats As mediacy.IQL.ObjectManager.BASIC_STATISTICS
'BASIC_STATISTICS
' Average
' Count
' CountOfMissing
' IndexOfMaximum
' IndexOfMinimum
' Maximum
' Mean
' Minimum
' NormalizedKurtosis
' NormalizedSkew
' Range
' RawKurtosis
' RawSkew
' StdDev
' Sum
' Variance
MyStats = ThisApplication.GlobalTools.McBasicStatistics(Prog_DataArrayHorizontal)
' 'Debug.Print "MyStats.Maximum"
' 'Debug.Print MyStats.Maximum
'Learn the CELL WIDTH or LENGTH STATS
textBox_H1D.Text = _
Trim(Format(MyStats.Count,"#,##0"))
textBox_H2D.Text = _
Trim(Format(MyStats.Minimum,"#,##0.00"))
textBox_H3D.Text = _
Trim(Format(MyStats.Maximum,"#,##0.00"))
textBox_MeanHoriCordLength.Text = _
Trim(Format(MyStats.Mean,"#,##0.00"))
This is my method. please give it a try.
Wesan
---------------------------------------------------------------------------------
Dim im As McImage = ThisApplication.ActiveImage