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
You can convert measurement outlines to ROI (e.g. using Features manager) and check image histogram (by default image histogram respects ROI).
Yuri
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:
Yuri
'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)}")
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