
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
- ADDING THE FEATURES TO THE FEATURE MANAGER
- CONVERTING THE FEATURES TO ROIS
- RECALLING THE FIRST ROI INTO CC AND GETTING THE HISTOGRAM
- 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

0
Best Answers
-
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
Yuri0 -
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
Yuri0
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).
Yuri0 -
2023-01-22-100015Yuri --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
0 -
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
Yuri0 -
2023-01-23-174217Yuri --Thank you for your guidance and the example code on this.I would like to avoid the screen flashing as the MEASUREMENT AREASIs 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
0 -
2023-01-24-110148Yuri --Thank you for that information and example code.-- Matt
0 -
2023-02-06-110213Yuri --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
0 -
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
Yuri0 -
2023-02-06-115424Yuri --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
0 -
2023-05-15-152105Yuri --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.-- MattORIGINAL IMAGE FROM JPG FILE (TIF FILE ATTACHED)HISTOGRAM OF ORIGINAL IMAGE WITH MONO INTERPRETATION OPTION OFFHISTOGRAM OF ORIGINAL IMAGE WITH MONO INTERPRETATION OPTION ON
0 -
2023-05-15-174154Yuri --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
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