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

What code will produce the results for each CLASS from LEARNING CLASSIFICATION?

All --

I have a methodology that divides a customer's samples into two classes using LEARNING CLASSIFICATION mechanism within PREMIER.

I would like to report the number of samples in each class.

My application is simulated in the attached image where PREMIER has identified 25 features within the image and then classified those features into:

    16 CIRCLE FEATURES
     9 SQUARE FEATURES

Can you please direct me to code that will produce:

    -- number of classes have been defined by LEARNING CLASSIFICATION
    -- name of each class that has been defined by LEARNING CLASSIFICATION
    -- count within each class that has been defined by LEARNING CLASSIFICATION

I have attached the TIF version of this image (with the CLASSIFIED FEATURES) to hopefully make creating a solution for this as easy as possible.  Unfortunately it looks like the TIF format retains the CLASSIFIED FEATURES but loses the CLASS NAMES.

Thanks.

-- Matt


Best Answer

  • Options
    edited August 2014 Answer ✓
    Hi Matt,

    Measurement Classes can be created by different methods (Threshold segmentation, Learning segmentation, Histogram classification,Manual,...). The macro below shows how to extract class information regardless the classes creation method:
    Imports MediaCy.Addins.Measurements
    ... 
        Public Sub PrintClassStats()
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub 'no image
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub'no data
            Dim classes As MMClasses=McMeasurements.ThisAddin.Options.Classes
            Dim nClasses As Integer=classes.Items.Count
            Debug.Print "Number of classes = " & nClasses.ToString
            For Each cl As MMClassDescr In classes.Items.Values
                'get count of objects of this class
                Dim nObj As Integer=0
                For Each sf As McMMSubFeature In md.SubFeatures
                    If sf.Value(eMeasures.AnyClass)=cl.Value Then nObj+=1
                Next
                Debug.Print "Class name = " & cl.DisplayName & ", Number of Objects = " & nObj.ToString
            Next
        End Sub
    The result for your image should look like:

    Number of classes = 2
    Class name = Square, Number of Objects = 9
    Class name = Circle, Number of Objects = 16

    You can visualize class statistics (number of objects per class) in the measurements histogram using Object:Class measurement (screenshot attached).

    Regarding TIFF: only measurement class index is saved to TIFF tag. Class parameters (names, colors, point shapes,...) are parts of global application options and not included into the tag, they are persistent and included into IQO file (measurement options). So if you want to restore the complete experiment, you should also save/load the IQO file.

    Regards,

    Yuri

Answers

  • Options
    Yuri --

    Thank you for your prompt response.

    The example code that you provided is a fantastic guide toward a solution for this customer.

    I was also able to follow your example about MEASURING OBJECT CLASSES and then VISUALIZING OBJECT CLASSES as a DATA HISTOGRAM.

    I see what you mean about the CLASS INDEX information within the PREMIER TIF FILE.  When I open the example image into PREMIER with my customer's options via their iqo file I get 16 features classified as CLOSED (CLASS 1) and and 9 features classified as OPEN (CLASS 2).

    I've included a SCREEN CAPTURE showing that all is working well.

    Thanks again.

    -- Matt
Sign In or Register to comment.