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 Answers

  • 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
  • edited May 2023 Answer ✓
    Hi Matt,

    Mono is calculated as weighted Gray (https://www.dynamsoft.com/blog/insights/image-processing/image-processing-101-color-space-conversion   ), like this:

    Grayscale = 0.299R + 0.587G + 0.114B

    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 2023
    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

  • 2023-05-15-152105

    Yuri --

    Thank you for your guidance on this.

    I am working on this APP with a TELEDYNE LUMENERA INFINITY5-5C DIGITAL CAMERA.

    I am working with the CAMERA in the 24-BIT COLOR MODE and then working with the HISTOGRAM in the 8-BIT MONOCHROME MODE.

    There is an issue though.

    In the images below IMAGE-PRO is reporting significantly different HISTOGRAMS and HISTOGRAM STATISTICS for the RGB INTERPRETATION of the RGB IMAGE and the MONO INTERPRETATION of the RGB IMAGE.

    Here are the HISTOGRAM STATISTICS for the SAME IMAGE with no active ROIs and the only difference being whether the MONO INTERPRETATION OPTION is OFF or ON.

       

    I am concerned because the MIN for RGB and the MIN for MONO are very different. 

    The MAX for RGB and MONO is also is different but not by as much.  It also seems that no matter what the IMAGE CONTENT, the MAX for the MONO INTERPRETATION will not be 255.

    Will you please look at this and see if there is an ISSUE with the MONO INTERPRETATION or if there is an explanation that I can pass along to the customer about this behavior?

    Also . . .

    The MONO INTERPRETATION HISTOGRAM does not seem to have any pixels in any bin above 192 but that is not what the STATISTICS say.

    Thank you very much.

    -- Matt

    ORIGINAL IMAGE FROM JPG FILE (TIF FILE ATTACHED)


    HISTOGRAM OF ORIGINAL IMAGE WITH MONO INTERPRETATION OPTION OFF

    HISTOGRAM OF ORIGINAL IMAGE WITH MONO INTERPRETATION OPTION ON


  • edited May 2023
    2023-05-15-174154

    Yuri --

    Thank you for that additional information.

    I think since the MONO is weighted heavily by the G CHANNEL in the RGB IMAGE, if the G CHANNEL is pulled away from 0 and 255, then the MONO HISTOGRAM will be pulled away from 0 and 255.

    In a properly LIT and WHITE BALANCED IMAGE, this should not be an issue.

    I will be able to work with on-site with the CUSTOMER and their SAMPLES, OPTICS, and CAMERA soon.

    Hopefully when the SYSTEM is WHITE BALANCED for their CONFIGURATION this will not be an issue.

    Thanks again.

    -- Matt




Sign In or Register to comment.