Home Image-Pro General Discussions

Calculate mean size of first x % of objects

Hi,

I'd like to run my own classification procedure.

Therefore I need to get the mean size of a predefined percentage of objects (not integrated in this test yet).

No problem to iterate through the objects, however, the sorting does not have any influence.

How do I get them sorted and the mean of e.g. the first 80% of objects?

Many thx

Daniel

Sub Test

Dim im As McImage=ThisApplication.ActiveImage
        If im Is Nothing Then Exit Sub
        Dim md As McMMData=im.MeasurementsData
Dim  ObjSize, x, countlimit, percentage

Debug.Clear


Debug.Print md.SubFeatures.Count
x = 0
percentage = 0.8
countlimit = Round(md.SubFeatures.Count * percentage)
Debug.Print countlimit

    With Measure.Measurements.TableCommands.Sort(Nothing)
            .Ascending = True
            .ColumnName = "mRgnArea"
            .Run()
        End With



        If md.SubFeatures.Count>0 Then

            For x = 0 To countlimit Step 1

        ObjSize = md.SubFeatures(x).Value(eMeasures.RgnArea)
        Debug.Print ObjSize
	

            Next x


        End If
end sub

Best Answer

  • Answer ✓
    Yes, that's the correct approach. Calling .Measurements.TableCommands.Sort just sorts the data table, not the data itself.

    Yuri

Answers

  • Hi to all,

    Solved the problem myself with Array.sort...

    Here the code:

    Sub Cluster_Correction
    
    'Daniel Havas 16 July 2015
    'this sub checks the running mean size of a deinfed percentage of objects and changes the numbercount if an object
    'is apparently larger than the mean.
    'A percentage of accounted basic objects can be defined and is evaluated
    'for each object, e.g. if 200 % larger than mean it is counted as two objects
    'can be used instead of a clusteranalysis to correct for the number of objects.
    
    
    Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
    Dim  ObjSize, x, countlimit, PercentObj, MOS, ActObjSize, PercentLarger, Corrnumber ', corrcount
    
    Debug.Clear
    'set vars
    x = 0
    PercentObj = 0.8
    PercentLarger = 2
    corrcount = md.SubFeatures.Count
    countlimit = Round(md.SubFeatures.Count * PercentObj)
    
    Dim list() As Single
    ReDim list(md.SubFeatures.Count)
    
    
            If md.SubFeatures.Count>0 Then
                For x = 0 To md.SubFeatures.Count-1 Step 1
                list(x) = md.SubFeatures(x).Value(eMeasures.RgnArea)
                Next x
            End If
    
    Array.Sort(list)
    
    x = 1
    If md.SubFeatures.Count>0 Then
    For x = 1 To countlimit Step 1
    
        Debug.Print x &"     " & list(x)
    
    ObjSize = ObjSize + md.SubFeatures(x).Value(eMeasures.RgnArea)
    
    Next
    
    ' calculate mean object size (MOS) of % objects
    MOS = ObjSize / countlimit
    End If
    
    Debug.Print MOS
    'iterate check each object
    
    x = 0
    If md.SubFeatures.Count>0 Then
                For x = 0 To md.SubFeatures.Count-1 Step 1
                ActObjSize = md.SubFeatures(x).Value(eMeasures.RgnArea)
    
                    If ActObjSize > MOS * PercentLarger Then
                    Corrnumber = md.SubFeatures(x).Value(eMeasures.RgnArea)/MOS
                    corrcount = corrcount + Round(Corrnumber,0)
    
                    End If
                Next x
            End If
    Debug.Print corrcount
    
    End Sub
Sign In or Register to comment.