Home Image-Pro Automation (Macros, Apps, Reports)

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

Thanks in advance.

-- Matt



Best Answers

  • Answer ✓
    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

  • edited March 2021 Answer ✓
    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,

    Yuri

Answers

  • 2021-03-26-141726

    Yuri --

    Thank you for the answer.

    I think the method that you suggest would certainly work but . . .

    I am already looping through the FEATURES in both of the CLASSES so I will just make a copy of the MEASUREMENTS that I need the STATS on and then get the STAT VALUES that I need.

    Thanks again.

    -- Matt





  • 2021-03-26-152939

    Yuri --

    Let me ask this question another way . . .

    The CODE below is in the AUTOMATION HELP under

    McMMData. CalcStatistics Method

    Dim OutStats(8) As Double
    ThisApplication.ActiveImage.MeasurementsData.CalcStatistics "mLnLength", OutStats
    Debug.Print "Mean Line.Length= " + OutStats(0)

    Is there a way to get:

    -- the MEAN (and other STATS (MIN, MAX, ETC)) LENGTH (or AREA, ETC) of the REGIONS that are in CLASS 0
    -- the MEAN (and other STATS (MIN, MAX, ETC)) LENGTH (or AREA, ETC) of the REGIONS that are in CLASS 1

    I am finding that the STATISTICAL FUNCTIONS are not easily accessed in VB.NET so knowing the above would be very helpful.

    Thanks.

    -- Matt

  • 2021-03-26-162530

    Yuri --

    I have managed to get the functionality I was looking for (and learn something in the process).

    The answer is / are LISTS.

    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 two classes of objects so I do the same thing for the other class and all is well.

    I hope this information is helpful to other folks here on this forum.

    -- Matt
  • 2021-03-29-110916

    Yuri --

    Thank you for the info about

        McBasicStatistics

    I had used that before (see below) but my memory and my searches through my CODE did not put that in front of me as an option.

    Hopefully the listing of info here about

        Lists

    and

        McBasicStatistics

    within IMAGE-PRO will be helpful to others here on the forum.

    Thanks again.

    -- Matt

    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

            'Calculate the STATS for the LENGTH RAW DATA

            Dim MyStats As mediacy.IQL.ObjectManager.BASIC_STATISTICS
            'BASIC_STATISTICS
            '  Average
            '  AbsDev
            '  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"))

  • edited June 2021
    Hi Matt,
    This is my method. please give it a try.

    Wesan
    ---------------------------------------------------------------------------------
    Dim im As McImage = ThisApplication.ActiveImage
    Dim dt As McMMData = im.MeasurementsData

                    'ClassStatistics method
            ThisApplication.Output.PrintMessage(dt.ClassStatistics(0, New MeasEntry(eMeasures.RgnArea)).Sum.ToString)  'ClassIndex:0
            ThisApplication.Output.PrintMessage(dt.ClassStatistics(0, New MeasEntry(eMeasures.RgnArea)).Mean.ToString)  'ClassIndex:0
            ThisApplication.Output.PrintMessage(dt.ClassStatistics(1, New MeasEntry(eMeasures.RgnArea)).Sum.ToString)  'ClassIndex:1
            ThisApplication.Output.PrintMessage(dt.ClassStatistics(1,New MeasEntry(eMeasures.RgnArea)).Mean.ToString)  'ClassIndex:1
    
            'CalcClassStatistics  method
            Dim OutStatsData(8) As Double
            dt.CalcClassStatistics(0, New MeasEntry(eMeasures.RgnArea), OutStatsData) 'ClassIndex:0
            ThisApplication.Output.PrintMessage(OutStatsData(5).ToString) 'Sum for class 0
            ThisApplication.Output.PrintMessage(OutStatsData(0).ToString) 'Mean for class 0
            dt.CalcClassStatistics(1, New MeasEntry(eMeasures.RgnArea), OutStatsData) 'ClassIndex:1
            ThisApplication.Output.PrintMessage(OutStatsData(5).ToString)
            ThisApplication.Output.PrintMessage(OutStatsData(0).tostring)
          
  • 2021-06-17-083713

    Wesan --

    Thank you for your suggestion.

    I will try this out.

    Thanks again.

    -- Matt




Sign In or Register to comment.