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

HISTOGRAMS FROM INDIVIDUAL MEASUREMENT AREAS . . .

2023-01-21-180412

All --

I have an IP10 APP that I am working on.

In that APP there are multiple MEASUREMENT AREAS in an IMAGE.  This is illustrated below as IMAGE BB.

I would like to know if there is CODE that will generate ARRAYS in a PROJECT containing the HISTOGRAM DATA for P1R1 and P1R2 in BB as I have done here by

  1. ADDING THE FEATURES TO THE FEATURE MANAGER
  2. CONVERTING THE FEATURES TO ROIS
  3. RECALLING THE FIRST ROI INTO CC AND GETTING THE HISTOGRAM
  4. RECALLING THE SECOND ROI INTO DD AND GETTING THE HISTOGRAM
A copy of BB.TIF with the BOUNDARIES is attached to this question.

Thanks.

-- Matt




BB.tif 274.9K

Best Answer

  • Answer ✓
    Hi Matt,

    I don't see screen flashing in my tests. Maybe you have other panels opened, such as Histogram, that are updated when ROI changes. You can close them.

    Anyway, to avoid flashing completely, you can do this operation on invisible image.
    Here is the modified macro:
        Public Sub GetHistogramOfSubfeature0
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub
            'get first subfeature
            Dim sf As McMMSubFeature=md.SubFeatures(0)
            Dim pts As Object
            sf.GetFeatures.GetFeaturePoints(sf.FeatureIndex,pts)
            Dim aoi As McRegions=im.Aoi
            If aoi.Count>0 Then aoi.Reset
            'create invisible image
            Dim im2 As McImage=im.Duplicate(mcImageCreateFlags.mcicfNotVisible Or mcImageCreateFlags.mcicfNoAddToCollection)
            Dim aoi2 As McRegions=im2.Aoi
            'set ROI from feature points
            aoi2.SetFeaturePoints(0,pts)
            'get histogram of ROI
            Dim hist As Mediacy.IQL.Operations.McHistogram=im2.Histogram
            Debug.Print ($"Mean = {hist.Mean(0)}")
            Debug.Print ($"Sum = {hist.Sum(0)}")
            im2.Close
        End Sub
    

    Yuri

Answers

  • Hi Matt,

    You can convert measurement outlines to ROI (e.g. using Features manager) and check image histogram (by default image histogram respects ROI).

    Yuri
  • 2023-01-22-100015

    Yuri --

    Thank you for that information.

    Is there a way in CODE to extract the HISTOGRAM DATA from the AREA MEASUREMENT OBJECTS without converting them into ROIs?

    Thanks again.

    -- Matt


  • edited January 23
    Hi Matt,

    If you want to use McHistogram, you must use ROI.
    It's easy to convert measurement outline to a ROI in a macro. Here is the macro that gets Histogram of the first measurement and prints Mean and Sum of the first channel:
    Imports MediaCy.Addins.Measurements
    Imports MediaCy.IQL.Features
    Imports Mediacy.IQL.Operators
    Imports Mediacy.IQL.Operations
    
    Public Module Module1
    
        Public Sub GetHistogramOfSubfeature0
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub
            'get first subfeature
            Dim sf As McMMSubFeature=md.SubFeatures(0)
            Dim pts As Object
            sf.GetFeatures.GetFeaturePoints(sf.FeatureIndex,pts)
            Dim aoi As McRegions=im.Aoi
            aoi.Reset
            'set ROI from feature points
            aoi.SetFeaturePoints(0,pts)
            'get histogram of ROI
            Dim hist As Mediacy.IQL.Operations.McHistogram=im.Histogram
            Debug.Print ($"Mean = {hist.Mean(0)}")
            Debug.Print ($"Sum = {hist.Sum(0)}")
        End Sub
    
    End Module
    

    Yuri
  • 2023-01-23-174217

    Yuri --

    Thank you for your guidance and the example code on this.

    I would like to avoid the screen flashing as the MEASUREMENT AREAS

    Is there a way to disable SCREEN UPDATES in IP10 so that the the process of converting the MEASUREMENT AREAS to ROIS is not shown to the user?

    If there is, I can disable SCREEN UPDATES, convert MEASUREMENT AREAS to ROIs individually, extract the HISTOGRAMS, and clear the last ROI, redraw the MEASUREMENT AREA, and enable SCREEN UPDATES.  That should keep the IMAGE FLASHING down to a minimum.

    Thanks again.

    -- Matt




  • 2023-01-24-110148

    Yuri --

    Thank you for that information and example code.

    -- Matt


  • 2023-02-06-110213

    Yuri --

    Thank you again for your EXAMPLE CODE for the extraction of the HISTOGRAM DATA.

    In your CODE

            'get histogram of ROI
            Dim hist As Mediacy.IQL.Operations.McHistogram=im.Histogram
            Debug.Print ($"Mean = {hist.Mean(0)}")
            Debug.Print ($"Sum = {hist.Sum(0)}")

    provides the HISTOGRAM DATA that I need if the IMAGE is MONO.

    I have attempted to work out how to modify this to get the MONO INTERPRETATION of an RGB IMAGE using the AUTOMATION HELP FILE but this page did not help.


    If an APP has an RGB IMAGE like the one on the left below (and attached), is a modification to your EXAMPLE CODE which will return the MONOCHROME HISTOGRAM (and STATISTICS) similar to the HISTOGRAM of the MONOCHROME IMAGE on the right below (and attached) that works well with your CODE?

    Thanks.

    -- Matt




  • Hi Matt,

    The Histogram property of the image has native interpretation corresponded to the type of the image (e.g. RGB or Mono).
    If you want to create a mono histogram of color image, you have to create a new McHistogram and set Interpretation to Mono. Here is the example:

        Public Sub GetMonoHistogram
            Dim im As McImage = ThisApplication.ActiveImage
            Dim hist As MediaCy.IQL.Operations.McHistogram = ThisApplication.CreateOperator("McHistogram",im)
            hist.Interpretation = mcInterpretation.mciMonochrome
            Debug.Print ($"Number of channels = {hist.NumberOfChannels}")
            Debug.Print ($"Mean = {hist.Mean(0)}")
        End Sub
    

    Yuri
  • 2023-02-06-115424

    Yuri --

    Thank you for your answer and the EXAMPLE CODE that it contains.

    I have run your CODE on the TWO EXAMPLE IMAGES in this DISCUSSION. 

    The CODE OUTPUT via DEBUG.PRINT of
    • Number of channels = 1
    • Mean = 171.469255372946
    for the RGB IMAGE and
    • Number of channels = 1
    • Mean = 192.248383354318
    for the MONO IMAGE show the same results as with the IMAGE HISTOGRAM WINDOWS shown earlier.

    Thank you very much.

    -- Matt

Sign In or Register to comment.