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



All --

I am attempting to extract the MEAN GRAY VALUE from an ROI within a 12bpp image.

The IMAGE HISTOGRAM gives me one value ((1687.88) and code that I have used before gives me a different value (1677.94).  Other STATS are different also.

Please see below.

Both of these values change with the size / position of the ROI so I believe that both are restricting their statistics to the ROI.

The values in the GUI match the values extracted from the same ROI using IMAGE-PRO PLUS.

Assistance resolving the difference between the value in the GUI and the CODE would be much appreciated.


-- Matt


Best Answer

  • Accepted Answer

    I was not aware that it was a sequence. The UI histogram is shown for ActiveFrame, but the macro histogram is calculated for all frames.

    Can you check it with single frame image?



  • Hi Matt,

    The histogram in a macro uses 256 bins by default, while the UI histogram uses 4096 bins on 12-bit images. You can set number of bins to 4096 to get the same stats:

        Public Sub PrintMean
            Dim hist As Mediacy.IQL.Operations.McHistogram=ThisApplication.ActiveImage.Histogram
            Debug.Print ("Mean =" & hist.Mean(0).ToString)
        End Sub


  • 2019-09-30-095009

    Yuri --

    Thank you for your response and your suggestion.

    I made the modification you suggested but MY CODE and the IP GUI still did not agree.  I pasted YOUR CODE into MY PROJECT and YOUR CODE and the GUI do not agree either.  Please see below.

    Also below are the SETTINGS for the IMAGE HISTOGRAM GUI. 

    I am running IP 10.0.4  which is also shown below.

    Your thoughts please?

    -- Matt

  • 2019-09-30-102724

    Yuri --

    Looking at your code, I tried the below.

    Public Sub PrintMean2
            Debug.Print ("Mean2 =" & ThisApplication.ActiveImage.Histogram.Mean(0).ToString)
        End Sub

    and got

    Mean2 =1677.76032498307

    Perhaps this is a clue as to what is happening and / or a way around it.


    -- Matt
  • Matt,

    Can you please try my code without modifications?
        Public Sub PrintMean
            Dim hist As Mediacy.IQL.Operations.McHistogram=ThisApplication.ActiveImage.Histogram
            Debug.Print ("Mean =" & hist.Mean(0).ToString)
        End Sub
    With and without ROI. How big is your image?

  • 2019-09-30-122923

    Yuri --

    In the screen captures above the PRINTMEAN CODE you provided was tested without modifications.

    The IMAGE DIMENSIONS are 696 x 520.

    The ROI DIMENSIONS are 211 x 91.

    The IMAGE is a SEQUENCE with 18 frames.

    Interpretation:    Monochrome (12bpp)   
    Number Of Channels:    1   
    Pixel Data Type:    Integer   
    Bits/Channel:    12   
    Bits/Pixel:    12   
    Bytes/Channel:    2   
    Bytes/Pixel:    2   
    Range Minimum:    0   
    Range Maximum:    4095   
    Camera Model:    Rolera XR   
    Camera ID:    35980   

    I hope this information is helpful.


    -- Matt


  • Matt, also please note that the UI McHistogram has its SamplingCoverage parameter set to 10.0, whereas the default (and thus that parameter value in your macro) is 100.0.  This won't make any difference with your test image, but with larger images (>4M pixels), the UI histogram is composed from sampled pixels, while the one from your macro will be full-coverage.  This is done for performance reasons to keep the UI histogram responsive as the active frame and/or ROI is changed.
  • 2019-10-01-103650

    Yuri and Craig --

    Thank you for your responses.

    Yuri --

    I have followed your suggestion.

    After setting the APPLY TO SEQUENCE / FRAME OPTION to FRAME, the CODE generates the same MEAN as the GUI.

    I created CODE named TESTER2 that demonstrates this. 

    SCREEN CAPTURES are shown below.

    Craig --

    Thank you for that information.  To understand your message, I asked IP to generate an image 10,000 x 10,000 pixels.  That should be 100,000,000 sq pixels in area.  The GUI HISTOGRAM for that image shows area as 915,658.  Perhaps it would be a suggestion for an improvement for IP that when this is happening in an image, that the GUI show a warning.  Perhaps something like the squiggly red underscore used by WORD (and others) when a spelling issue has been identified or the squiggly green underscore used by WORD when a grammar issue has been identified.

    Thanks again.

    -- Matt


  • 2019-10-01-111153

    Yuri --

    I am not having success querying
    to determine the current state of the SEQUENCE / FRAME OPTION.

    I would like my CODE to put this OPTION back where it was after I turn on the FRAME OPTION and then extract the ROI MEAN INTENSITY.

    Will you please direct me to CODE that I can use for this?


    -- Matt
  • Matt,

    Mode property of McHistogram controls Frame/Image access:

        Public Sub PrintMean
            Dim hist As Mediacy.IQL.Operations.McHistogram=ThisApplication.ActiveImage.Histogram
            Debug.Print ("Mean =" & hist.Mean(0).ToString)
        End Sub

    You can check automation help for more options, search for IMcHistogram (or mcHistogramMode).


  • edited October 2019

    Yuri --

    Thank you for the additional information.  I think your CODE would select the FRAME OPTION for the HIST VARIABLE without changing the OPTION for the WINDOW.  I will try that out.

    I restarted IP and found that it seems like the

    Is also working off a BIN COUNT = 256 because it generates an incorrect result unless something like

            Dim hist As Mediacy.IQL.Operations.McHistogram = _
            hist.BinCount = _
                2 ^ ThisApplication.ActiveImage.BitsPerChannel
    is run before something like

            With View.ImageViewCommands.Options(Nothing)
                .UseActiveFrameRange = False
            End With
            'UPDATE THE ROI MEAN
            Debug.Print _
                ( _
                "TESTER2 MEAN = " & Format(ThisApplication.ActiveImage.Histogram.Mean(0),"0.000") _

    is run.

    I'll weave YOUR CODE and MY CODE together now that I have a couple of ways to get the correct number via CODE.

    Thanks again for your guidance on this.

    -- Matt

Sign In or Register to comment.