Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting area, mean, variance, and max pixel value for an ROI

I am using Vision for Visual Basic and I want to get the area, mean, variance, and maximum pixel value for an ROI.

I have written the following code, but I get an Invalid Index error on the line: Qregion = regionsReport.Item(1)

' display the roi on the screen
Me.imaqDisplay.Regions.RemoveAll
Set Qrect = New CWIMAQRectangle
Qrect.Left = Me.txtX1.Text
Qrect.Top = Me.txtY1.Text
Qrect.Width = Me.txtX2.Text - Me.txtX1.Text
Qrect.Height = Me.txtY2.Text - Me.txtY1.Text

Me.imaqDisplay.Regions.AddRectangle Qrect

' get the stats for the roi
Me.CWIMAQVision1.Quantify M
e.imaqDisplay.Image, globalReport, regionsReport
Qregion = regionsReport.Item(1) ' get Invalid Index error on this line
frmTestValues.txtArea.Text = Qregion.Area
frmTestValues.txtMean.Text = Qregion.Mean

It seems like I may be missing something here. Can anyone tell me what I might be doing wrong?

Thanks.
0 Kudos
Message 1 of 2
(3,467 Views)
bep -

The CWIMAQVision.Quantify method takes in a mask parameter which it uses to determine the regions on which to quantify. So, after adding the rectangle to your regions object, add the following lines of code (you'll need to add "Dim maskImage As New CWIMAQImage" and "Dim numParticles As Variant" at the top of this function):

maskImage.Type = cwimaqImageTypeU8
Me.CWIMAQVision1.RegionsToMask maskImage, Me.imaqDisplay.Regions
Me.CWIMAQVision1.Label maskImage, maskImage, numParticles

and then the quantify statement will become:
Me.CWIMAQVision1.Quantify Me.imaqDisplay.Image, globalReport, regionsReport, maskImage

Let me know if you have problems with this approach. Thanks!

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
Message 2 of 2
(3,467 Views)