Adjusting the RELATIVE SIZE MEASUREMENT in PREMIER . . .

2017-05-29-113738

All --

I am working to use the RELATIVE SIZE MEASUREMENTS in PREMIER (using V9.3 BUILD 6468) for a customer doing CELL COUNTS and it doesn't work properly on a TEST IMAGE.

In the DOTS A IMAGE on the LEFT below there are 100 measurement objects representing 100 individual dots. 

In the DOTS B IMAGE on the RIGHT below there are 93 measurement objects representing the same 100 dots.

Unfortunately in the DOTS B IMAGE the clusters of 2, 3, and 4 generate RELATIVE SIZE MEASUREMENTS of 1, 2, and 4 and the SUM of the RELATIVE SIZES for DOTS B is 97.  This is off from the ACTUAL by 3.

Is there any adjustment within PREMIER to overcome this?

Copies of the DOTS A IMAGE and the DOTS B IMAGE are attached.

Thanks.

-- Matt

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


Best Answers

  • Accepted Answer
    The "Relative Size" measurement is described in the popup as "Size as an integral multiple of the size of the smallest selected regions".  So the short answer to your question is the result you are getting is due to rounding down associated with the conversion of floating point areas to integral values.  The long answer follows:

    The measurement was inherited from Image-Pro Plus HAIL where it was called "Cluster". Here are some early notes that I made in the code when porting the HAIL measurements to IQL; these notes describe why I decided to change its name from "Cluster" to "Relative Size":

    BLBM_CLUSTER issues:

    What is the "Cluster" measurement supposed to measure?  The ImagePro Plus v4.0
    help says this about it:

    "Cluster: A cluster is a group of objects defined by an AOI. Cluster reports the
    number of individual objects contained within the outline."

    BUT, this is not even approximately what is actually measured by the Cluster
    measurement.  As computed, the measurement should actually be called something
    like "Relative Size", because the measurement value is the ratio, cast to an
    integer, of the sub-region's Area to the mean area of the smallest sub-regions.
    Unlike all other measurements, this one includes only "selected" sub-regions
    when computing the results.

    Thus the Cluster measurement has nothing to do with AOI's and nothing to do with
    adjacent regions.  And except for the computation of the mean of the smallest
    sub-regions, the value for any one sub-region has nothing to do with any other
    sub-region!

    You could sort by Cluster to get sub-regions ordered approximately by Area, but
    you could accomplish the same thing (with more accuracy) by just sorting by
    Area.

    Does anyone use this measurement?  If so, do they know what they are measuring?
    The Count-Size Cluster dialog basically divides regions into two groups: the
    smallest ones and all others?  How often is this useful?  If you are going to
    classify groups of sub-regions by relative size, shouldn't you be able to
    specify the number of groups and also have some better method of picking the
    dividing point(s) between groups?

    And then what about supplying some actually useful spatial clustering
    measurements.  For example, for each feature, how many other features are within
    some distance of this one?  What is the location of the weighted (or unweighted)
    center of the cluster of features of which this one is a part.  And so on.

    So what I did was to change the BLBM_CLUSTER to BLBM_RELSIZE_WASCLUSTER and
    changed the measurement name to mRelativeSize?  I renamed the function below,
    which used to be named "GetClusterStat" and renamed a bunch of variables to
    indicate what they actually measure.  The old name (mObjectsPerCluster) was
    totally misleading as evidenced by the fact that the IPP4 documentation writers
    got it totally wrong.

    As you can see, I'm not much of a fan of this measurement and we have subsequently added many of the classifier abilities I was talking about, but it was included in IQL without any change (other than the name) for back-compatibility with HAIL measurements.  I suspect it was added due to some specific request to analyze images similar to DOTSB image: that is, images where objects of similar size are sometimes (though not usually or the algorithm wouldn't work) clustered together.  In this case only clustered objects will have a value other than 1, with the integral value giving the approximate size of the clustering.  The algorithm would work better if the results were rounded to the nearest integer rather than down to the next lowest integer, and the identification of the non-clustered objects needs work (i.e., in your case the two-dot cluster is actually included in the non-clustered group), but as I said, the measurement was kept without changing the algorithm.

    The algorithm really does fail for the clumping in DOTSB where, clearly, your clumps should be assigned the next higher integral value.  The two-dot clump is especially disturbing since it is labeled with the same value, 1, as all of the non-clumped dots (due to overlap, its area is less than twice the mean of the single dots, so it gets included in the "small" group).

    However, since all of the legacy users of the HAIL "Cluster" measurement are probably retired or dead, we'll consider fixing the algorithm for a future version of Premier.

     

  • Accepted Answer
    Hi Matt,

    We will look at the ways to make Relative Size measure more flexible, but you can also use user-defined measures to get the values you need right now. Premier has ability to create user-defined measurements, so they look like native, built in measures. I've attached a project that will give you "Adjusted Count" measure (analog of Relative Size), which counts clusters properly, so you end up with 100 objects in total (just load the attached app to Premier and click Count):


    Below is the function that does the calculation of the measure. It's based on the Minimum*1.05 and it's properly rounded up to the closest integer value.

        Private Sub _meas_ComputeValue(ByVal MeasurementObject As MediaCy.IQL.Features.IMcMeasure, ByVal ParentOperator As Object, ByRef vValue As Object) Handles _meas.ComputeValue
            Dim myRegions As McRegions=ParentOperator
            Dim nObj As Integer=myRegions.Count
            If nObj=0 Then Exit Sub
            Dim om As McOMGlobal=ThisApplication.Engine.McObjects.GlobalTools
            With om
                Dim vals() As Double
                ReDim vals(nObj-1)'allocate output array
    
                'get area of objects
                Dim measArea As IMcMeasure=myRegions.mRgnArea
                'calculate area stats
                Dim bst As MediaCy.IQL.ObjectManager.BASIC_STATISTICS=.McBasicStatistics(measArea.value)
    
                Dim SingleObjectArea As Double
                SingleObjectArea=bst.Minimum*1.05'set single object area as Min*1.05
                'activate this line if the single object area should be a fixed value
                'SingleObjectArea=80'set fixed value
    
                'calculate Adjusted Size
                For i As Integer=0 To nObj-1
                    Dim area As Double=measArea.value(i)
                    'calculate Adjusted Count as rounded value limiting to 1
                    vals(i)=System.Math.Max(1,System.Math.Round( area/SingleObjectArea))
                Next
                'output object
                Dim mcobjVal As MediaCy.IQL.ObjectManager.McObject=.McOpAdd(vals,0)
                vValue= mcobjVal 'return the McObject result
            End With
        End Sub
    

    You can edit this code if you need to have different overlap percentage or just use a fixed value for single object area.

    Yuri
  • Accepted Answer
    Matt, the next release of Premier will have a fix that corrects the "rounding-down" problem for the Relative Size measurement.
  • Accepted Answer
    Hi Matt,

    Sorry for the delay with response. It looks like the forum notifications stopped working. We will check it.

    Here is a sample macro that prints Sum of AdjustedMeasure
        Public Sub PrintSum
            Dim md As MediaCy.Addins.Measurements.McMMData=ThisApplication.ActiveImage.MeasurementsData
            'MeasurementEntry for the measure
            Dim measAdjustedSize As New MeasEntry("AdjustedSize")
            'print stats value
            Debug.Print md.Statistics(measAdjustedSize).Sum
        End Sub
    You can run this macro from any project, the only condition is that the AdjustedSizeMeasure project is loaded to Premier.

    Yuri

Answers

  • 2017-05-30-100239

    Craig and Yuri --

    Thank you for your responses and the information they contain.

    I'll digest the information and work with the CODE SAMPLE later today.

    I hope RELATIVE SIZE (or an OFFSPRING like RELATIVE SIZE 2) gets some TLC.  It would be a very good match for applications like STAINED CELL COUNTING.

    -- Matt
  • 2017-06-02-1733

    Craig --

    Thanks for the info and the plan to address this.

    Yuri --

    I'll be wiring your solution into an APP for a PREMIER USER this weekend.

    Thanks both of you.

    -- Matt
  • 2017-06-05-104013

    Yuri --

    Thank you again for your assistance with this issue.

    In the SCREEN CAPTURE below, you will see that I was able to use your code to add ADJUSTED COUNT to the MEASUREMENT DATA TABLE.

    I have encountered a bit of a hurtle though.

    In the code below, the first (commented) section is how I was getting the SUM of the RELATIVE SIZE MEASUREMENTS from the FEATURES found by a PREMIER COUNT.

    In the second (uncommented) section of the code below is how I was attempting to get the SUM of the ADJUSTED SIZE that is now a part of the MEASUREMENT DATA TABLE.

    When the APP tries to execute the second section of code, PREMIER displays a SPECIFIED CAST IS NOT VALID error for the command that includes the .sum.

    I assume this is because the ADJUSTED SUM is not available to DATA STATISTICS in the same way that NATIVE MEASUREMENT of FEATURE RELATIVE SIZES are.

    Is there an elegant way around this?

    If not, I can use something like

        MyStats = ThisApplication.GlobalTools.McBasicStatistics(MyDataArray)

    but I'll need an array of the ADJUSTED SUM VALUES?  Can you direct me to how I can get that?

    Thanks.

    -- Matt



    '                textBox_POSCellCount.text = _
    '                    Trim(Format(data.Statistics(eMeasures.RgnRelativeSize).sum,"#,##0"))
    
                    textBox_POSCellCount.text = _
                        Trim(Format(data.Statistics("AdjustedSize").sum,"#,##0"))


  • 2017-06-05-141346

    Yuri --

    I started toward resolving the issue noted above with the code below.

    It seems that I cannot access the INDIVIDUAL ADJUSTED COUNT VALUES in the same way that I can access the INDIVIDUAL RELATIVE SIZE VALUES.

    When the APP tries to execute

                            'Build the string that will send the data row to the output window
                            MyString = _
                                Str(i) & vbTab & _
                                Str(feature.Value("AdjustedSize")) & vbTab & _
                                ""
    

    a SPECIFIED CAST IS NOT VALID ERROR is displayed.

    It seems that this is basically the same issue as trying to get the STATISTICS on the USER DEFINED MEASUREMENT.

    Will you direct me how to get the ADJUSTED COUNT VALUES and / or how to get the ADJUSTED COUNT SUM please?

    Thanks.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
            'Connect with the MEASUREMENT DATA
            Dim data As McMMData
            With measure.MeasurementsCommands.GetData(Nothing)
                .Run(ThisApplication.ActiveDocument, data)
            End With

    and

                    'Loop through the features found in the current image document
                    For i As Integer = 0 To data.Rows-1
    
                            'Learn about the data for feature i
                            Dim feature As McMMSubFeature = data.SubFeature(i)
    
                            'If i = 0
                            If (i = 0) Then
    
                                'Then
    
                                'Build the string that will send the header row to the output window
                                Dim MyString As String = _
                                    "Feature" & vbTab & _
                                    "Adjusted Count" & vbTab & _
                                    ""
    
                                'Send the string to the output window
                                ThisApplication.Output.PrintMessage(MyString)
    
                            End If
    
                            'Build the string that will send the data row to the output window
                            MyString = _
                                Str(i) & vbTab & _
                                Str(feature.Value("AdjustedSize")) & vbTab & _
                                ""
    
                            'Send the string to the output window
                            ThisApplication.Output.PrintMessage(MyString)
    
                        Next

  • 2017-06-06-094054

    Yuri (and others) --

    Is there a way for my code to access the ADJUSTED COUNT VALUES or get the SUM for the ADJUSTED COUNT POPULATION?

    Thanks.

    -- Matt
  • 2017-06-06-165252

    Yuri --

    Thank you for the assistance.

    I'll add that code to the APP the next time I pop the hood.

    I worked around this by doing COUNT = TOTAL AREA / MIN AREA.

    Thanks again.

    -- Matt

Sign In or Register to comment.