Options
BEST CODE TO GET STATISTICS FOR AN ARRAY OR A LIST . . .
20230116155334
All 
I am working on an APP that has a bunch of different ARRAYS of MEASUREMENTS from a bunch of different IMAGES.
The APP needs to be able to CALCULATE and DISPLAY the STATISTICS for each of the ARRAYS.
In a DISCUSSION in MAY2015, I was directed to
ThisApplication.GlobalTools.McBasicStatistics
and that works but at some point I was able to use LISTS and CODE for VB.NET that gets the STATISTICS with something like
This was discussed in a DISCUSSION in MAR2021 but I cannot seem to get the LISTS to show the STATISTICAL TOOLS like I seemed to be able to when I did this
***
After declaring a LIST in IP10 with something like this
Dim Prog_ListLengths1 As New System.Collections.Generic.List(Of Double)
and then adding my Lengths to the LIST with something like this
'REMEMBER THE LENGTH OF THIS FEATURE
Prog_ListLengths1.add _
( _
sf.Value(eMeasures.RgnLength) _
)
Then I can get the STATS from the LIST with something like this
Debug.Print Prog_ListLengths1.Min Debug.Print Prog_ListLengths1.Max Debug.Print Prog_ListLengths1.Average
***
I have created and attached a DEMONSTRATION PROJECT in
Array Statistics Project V1A.ipx
that has a DEMO ARRAY, a DEMO LIST, and a determination of a STANDARD DEVIATION using
Dim MyStats As mediacy.IQL.ObjectManager.BASIC_STATISTICS = _ ThisApplication.GlobalTools.McBasicStatistics(MyDemoArray) textBox3.Text = _ "The STANDARD DEVIATION for MyDemoArray is " & Format (MyStats.StdDev,"#,##0.00")
Is there a better way to get the STATISTICS for the DEMO ARRAY or the DEMO LIST?
Thanks.
 Matt
0
Best Answers

OptionsHi Matt,
System.Linq with .NET IEnumerable interface provides functions for simple statistics, such as Min, Max, Sum, Average. Check this link: https://learn.microsoft.com/enus/dotnet/api/system.linq.enumerable?view=netframework4.8
If you need Standard Deviation for any array, then you have to use something else, such as McBasicStatistics.
If you are trying to get statistics of Measurements, then you can use Statistics property of McMMData: https://help.mediacy.com/ImagePro/Automation/11/html/Properties_T_MediaCy_Addins_Measurements_StatsClass.htm
Here is an example that prints standard deviation of Area of the objects in active image:Public Sub MeasurementStats() Dim md As Mediacy.Addins.Measurements.McMMData=ThisApplication.ActiveImage.MeasurementsData Debug.Print ($"Standard deviation of Area = {md.Statistics(MediaCy.Addins.Measurements.eMeasures.RgnArea).StdDev}") End Sub
Yuri
0 
OptionsHi Matt,
As you pointed out, there are different ways to calculate Standard Deviation. Wikipedia page shows 3 equations (uncorrected, corrected, unbiased) : https://en.wikipedia.org/wiki/Standard_deviation
ImagePro uses the "uncorrected" formula with N in denominator (also called standard deviation of entire population). Excel also has this function, it's called STDEVPA. The difference between STDEVA and STDEVPA is very small for large number of objects.
If you need a specific version, you can use the conversion formula as in your sample.
Yuri0
Answers
Thanks for that info.
Thanks again.
Format(System.Math.Sqrt((MyStats.Variance)*(MyStats.Count)/(MyStats.Count1)),"#,##0.000")