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

Trigger a SINGLE CLASSIFICATION . . .

2017-02-14-114741

All --

If I have:

** An image with a set of MEASUREMENT OBJECTS
** A SINGLE CLASSIFICATION (lets say SMALL AREAS and BIG AREAS) set up and stored in an IQO file
** The SINGLE CLASSIFICATION recalled into PREMIER

how do I TRIGGER the CLASSIFICATION so that the the MEASUREMENT OBJECTS are assigned by SINGLE CLASSIFICATION FEATURE into

** SMALL AREAS
** BIG AREAS

When I do this manually and record the steps I get

        With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
            .Measurement =  New MeasEntry(eMeasures.RgnRelativeSize)
            .BinRanges = New Double() {1R,2R,3R,4R,5R,6R,7R,8R,9R,10R}
            .Run(doc1)
        End With

but this looks like it is this is actually superseding the BIN LIMITS that have been recalled from the IQO FILE.

Is there way to TRIGGER the CLASSIFICATION without including the BIN LIMITS in the PROJECT CODE?

I would go ahead and set the BIN LIMITS in the CODE and proceed but I have tweaked the BIN COLORS in the IQO FILE also and I don't want to have to do that in the CODE if I can avoid it.

Thanks.

-- Matt

Best Answers

  • Answer ✓
    Ok, I understend now. So you will need:
    1. Load IQO file. (which also loads classification ranges to the active image options)
    2. Execute Count  .
    3. Classify objects using SingleVariable classification with the parameters from the options.

    Here is the sample macro:

       Public Function ClassifyClusters()
    
            Dim doc1
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            With Measure.Measurements.OptionsCommands.Open(Nothing)
                .FileName = ThisApplication.Path(mcPathType.mcptConfigurationFiles) & "test.iqo"
                .FilterIndex = 1
                .Run(doc1)
            End With
    
            'Execute Count to get counted objects
            With Measure.MeasurementsCommands.ExecuteCount(Nothing)
                .Run(doc1)
            End With
    
            Dim md As McMMData=ThisApplication.ActiveImage.MeasurementsData
            'classify using the ranges from the Options
            With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
               .Measurement =  New MeasEntry(md.SingleVarClassification.Measurement)
               .BinRanges = md.SingleVarClassification.BinRanges
               .Run(doc1)
            End With
    
        End Function

    Yuri

  • Answer ✓
    Yes, classification command resets the classes, so reloading them again from the options will restore colors.

    Yuri

Answers

  • Hi Matt,

    If you want to classify by fixed ranges, just run the ClassifyByMeasurement command in your macro, where you define bins. Does it work for you?
    You can also set class names and color by macro running such command after classification:

            With Measure.MeasurementsCommands.Options(Nothing)
                .ActiveClass = 2
                .Classes = New System.Collections.Generic.List(Of MMClassDescr)
                   .Classes.Add(New MMClassDescr("Live",System.Drawing.Color.Lime,ePointShape.LargeTarget45))
                   .Classes.Add(New MMClassDescr("Dead",System.Drawing.Color.Red,ePointShape.LargeTarget90))
                    
              .Run(doc1)
            End With
    
            'refresh
            Mediacy.Addins.Measurements.McMeasurements.ThisAddin.UpdateControls(Mediacy.Addins.Measurements.Globals.eChangeFlags.Data)
    
    

    Yuri

  • 2017-02-14-130416

    Yuri --

    Thank you for your prompt response.

    I do not understand your suggestion regarding

        ClassifyByMeasurement

    I commented out the

            With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
                .Measurement =  New MeasEntry(eMeasures.RgnRelativeSize)
                .BinRanges = New Double() {1R,2R,3R,4R,5R,6R,7R,8R,9R,10R}
                .Run(doc1)
            End With

    and I added

            'refresh
            Mediacy.Addins.Measurements.McMeasurements.ThisAddin.UpdateControls(Mediacy.Addins.Measurements.Globals.eChangeFlags.Data)
    

    but the CLASSIFICATION did not happen.

    The whole FUNCTION is below and a SCREEN CAPTURE of the SINGLE CLASSIFICATION (maybe that's what you mean by CLASSIFY BY MEASUREMENT) is shown below that.  This is the CLASSIFIER that is saved in the IQO FILE.

    Thanks again.

    -- Matt


        Public Function ClassifyClusters()
    
            Dim doc1
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            With Measure.Measurements.OptionsCommands.Open(Nothing)
                .FileName = MacroDir & "\Measurement Options -- Cluster Classes.iqo"
                .FilterIndex = 1
                .Run(doc1)
            End With
    
    '        With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
    '            .Measurement =  New MeasEntry(eMeasures.RgnRelativeSize)
    '            .BinRanges = New Double() {1R,2R,3R,4R,5R,6R,7R,8R,9R,10R}
    '           .Run(doc1)
    '        End With
    
     'refresh
            Mediacy.Addins.Measurements.McMeasurements.ThisAddin.UpdateControls(Mediacy.Addins.Measurements.Globals.eChangeFlags.Data)
    
    
        End Function




  • You have to execute classification command, uncomment it to see the result.

    Yuri
  • 2017-02-14-135910

    Yuri --

    When I started working on this, I tried the

            With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
    '            .Measurement =  New MeasEntry(eMeasures.RgnRelativeSize)
    '            .BinRanges = New Double() {1R,2R,3R,4R,5R,6R,7R,8R,9R,10R}
               .Run(doc1)
            End With

    to see if that would make trigger the CLASSIFICATION but I got an error.

    If this is not what you mean by uncommenting the execute, will you please make the mod you suggest to the FUNCTION and include it in your reply?

    Thanks.

    -- Matt

  • You have to uncomment everything.

    Yuri
  • 2017-02-14-163339

    Yuri --

    I understand now. 

    When I make the CODE read

        Public Function ClassifyClusters()
    
            Dim doc1
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            With Measure.Measurements.OptionsCommands.Open(Nothing)
                .FileName = MacroDir & "\Measurement Options -- Cluster Classes.iqo"
                .FilterIndex = 1
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
               .Measurement =  New MeasEntry(eMeasures.RgnRelativeSize)
               .BinRanges = New Double() {1R,2R,3R,4R,5R,6R,7R,8R,9R,10R}
               .Run(doc1)
            End With
    
        End Function

    everything works properly but the code has the NUMBER OF BINS and the BIN LIMITS hardwired in.

    I am trying to avoid this.

    Is there a way to use

     'refresh
     Mediacy.Addins.Measurements.McMeasurements.ThisAddin.UpdateControls(Mediacy.Addins.Measurements.Globals.eChangeFlags.Data)
    

    or another statement to trigger the CLASSIFICATION BY MEASUREMENT after it is configured by the IQO FILE?

    Thanks.

    -- Matt

  • Matt, if you don't want hardwired limits and bins, what exactly do you want?

    Yuri

  • 2017-02-14-165509

    Yuri --

    I have configured the CLASSIFY BY MEASUREMENT and saved this in an IQO FILE.

    I would like to FIND the MEASUREMENT OBJECTS and then run the

        Function ClassifyClusters()   

    to recall the IQO FILE, and trigger the CLASSIFICATION.

    If I make the IQO FILE the mechanism for holding the NUMBER OF BINS, BIN LIMITS, and BIN CLASS COLORS, then I can change this easier based on the END USER REQUIREMENTS.

    I hope this information helps.

    Thanks.

    -- Matt

  • 2017-02-14-171602

    Yuri --

    Based on the CODE you provided, I have modified the ClassifyClusters Function as shown below.

    Since a COUNT has been done before this function is called, that part of your CODE was not needed.

    Since the COLORS used by the CLASSIFICATION are somehow reset to the PREMIER DEFAULTS by the code under

        'Trigger the CLASSIFY BY MEASUREMENT

    I had to recall the IQO FILE again to get the COLORS for the CLASSES to match the needs of the END USER.

    Thank you very much for providing this much needed assistance.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
        Public Function ClassifyClusters()
    
            'Declare LOCAL VARIABLES
            Dim doc1
    
            'Connect with the IMAGE
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            'Recall the CLASSIFY BY MEASUREMENT using the IQO FILE
            With Measure.Measurements.OptionsCommands.Open(Nothing)
                .FileName = MacroDir & "\Measurement Options -- Cluster Classes.iqo"
                .FilterIndex = 1
                .Run(doc1)
            End With
    
            'Trigger the CLASSIFY BY MEASUREMENT
            Dim md As McMMData=ThisApplication.ActiveImage.MeasurementsData
            'classify using the ranges from the Options
            With Measure.MeasurementsCommands.ClassifyByMeasurement(Nothing)
               .Measurement =  New MeasEntry(md.SingleVarClassification.Measurement)
               .BinRanges = md.SingleVarClassification.BinRanges
               .Run(doc1)
            End With
    
            'Recall the IQO FILE again to set the CLASSIFICATION COLORS
            With Measure.Measurements.OptionsCommands.Open(Nothing)
                .FileName = MacroDir & "\Measurement Options -- Cluster Classes.iqo"
                .FilterIndex = 1
                .Run(doc1)
            End With
    
        End Function
    

  • Hi Matt, 

    Since you helped me that nicely with the file read - would you be interested in a cluster correction solution I use and which is independent from iqo files? 

    I define a percentage of number of objects, calculate their mean size in a bubble sorted vector and then mathematically correct all further objects by checking their current size and count up if they supersede a defined limit (e.g. 250% of the mean size of single objects). 

    This way you could also cluster-correct within classified objects, e.g. three classes of cells and in all three there might be singles and clusters...

    Tell me if you're interested - if yes, I'll have to detangle the code and explain some globals that the code makes sense for you. 

    Best
    Daniel

  • 2017-02-16-095438

    Daniel --

    Thank you for your kind offer.

    The RELATIVE SIZE MEASUREMENT within PREMIER seems to be performing well enough for the application that I'm working on and I believe that it may be performing an operation very similar to the operation you have described.

    The CLASSIFY BY MEASUREMENT mechanism is only being used to change the COLOR of the MEASUREMENT OBJECTS that are overlaid on the IMAGE by using 9 CLASSES based on RELATIVE SIZE.  The bins from 1 to 8 are COUNTS 1 to 8.  Bin 9 is 9 and more.  I have fiddled with the COLORS so that 1 is green, 2 is yellow, 3 is orange, 4 is red . . . I found that the normal COLORS for the CLASSES were too similar from BIN 1 to BIN2 . . . so I scrambled them so BIN 1 is significantly different from BIN 2 . . .

    I hope this information provides some ideas for you to use in your apps.

    Thanks again for your kind offer.

    -- Matt
  • O.k. - if you come to the point to make cluster-correction in several classes that you e.g. defined by the learning function then keep it in mind... The issue is that bins can work fine, but objects can simply individually differ in size from image to image. Bins don't mind, my way does :-) Just keep it in mind if you ever need it. 
    Thanks

    Dan
  • Dan --

    Will do.

    You may get some other folks interested in your code also since the information you have provided should show up in the FORUM SEARCH.

    Thanks again.

    -- Matt
Sign In or Register to comment.