DIFFERENT HISTOGRAM STATISTICS from GUI and CODE . . .
2019-09-27-182941
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.
Thanks.
-- Matt
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


0
Best Answer
-
Matt,
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?
Yuri
0
Answers
-
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 hist.BinCount=4096 Debug.Print ("Mean =" & hist.Mean(0).ToString) End Sub
Regards,
Yuri
0 -
2019-09-30-095009Yuri --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
0 -
2019-09-30-102724Yuri --Looking at your code, I tried the below.
Public Sub PrintMean2 Debug.Print ("Mean2 =" & ThisApplication.ActiveImage.Histogram.Mean(0).ToString) End Sub
and gotMean2 =1677.76032498307Perhaps this is a clue as to what is happening and / or a way around it.Thanks.-- Matt0 -
Matt,
Can you please try my code without modifications?Public Sub PrintMean Dim hist As Mediacy.IQL.Operations.McHistogram=ThisApplication.ActiveImage.Histogram hist.BinCount=4096 Debug.Print ("Mean =" & hist.Mean(0).ToString) End Sub
With and without ROI. How big is your image?
Yuri0 -
2019-09-30-122923Yuri --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.The IMAGE TYPE INFO isInterpretation: 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: 35980I hope this information is helpful.Thanks.-- Matt
0 -
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.
0 -
2019-10-01-103650Yuri 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-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
0 -
2019-10-01-111153Yuri --I am not having success querying
view.ImageViewCommands.Options(Nothing).UseActiveFrameRange
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?Thanks.-- Matt0 -
Matt,
Mode property of McHistogram controls Frame/Image access:Public Sub PrintMean Dim hist As Mediacy.IQL.Operations.McHistogram=ThisApplication.ActiveImage.Histogram hist.BinCount=4096 hist.Mode=MediaCy.IQL.Operations.mcHistogramMode.mchmProcessActiveFrameOnly Debug.Print ("Mean =" & hist.Mean(0).ToString) End Sub
You can check automation help for more options, search for IMcHistogram (or mcHistogramMode).
Yuri
0 -
2019-10-01-120244Yuri --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
ThisApplication.ActiveImage.Histogram.Mean(0)
Is also working off a BIN COUNT = 256 because it generates an incorrect result unless something likeDim hist As Mediacy.IQL.Operations.McHistogram = _ ThisApplication.ActiveImage.Histogram hist.BinCount = _ 2 ^ ThisApplication.ActiveImage.BitsPerChannel
is run before something like'SELECT THE SINGLE FRAME MODE With View.ImageViewCommands.Options(Nothing) .UseActiveFrameRange = False .Run(ThisApplication.ActiveWindow) 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
0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions