02-11-2010 08:26 PM
I am trying to use the Quantify function to get statistics on multiple regions within an image. The documentation for the Quantify function states:
Quantifies the contents of an image or the regions within an image. The region definition is performed with a labeled image mask. Each region of the mask has a single unique value.
How do I create the labeled image mask?
Thanks!
02-11-2010 10:05 PM
Do you have vision assistant. You can simply choose multiple regions like this.
02-12-2010 11:57 AM - edited 02-12-2010 11:57 AM
Hi Steverino,
There should be an example for defining a mask here: C:\Program Files\National Instruments\Vision\Examples\MSVB.NET\2. Functions\Image Management\mask
Give that a try. All of your text-based examples will show up in the Examples folder in the directory above. This is a great resource.
Cheers.
02-12-2010 04:57 PM
Thanks for your inputs, but unfortunately they do not move closer to a solution.
I tried Vision Assistant and the creating .NET code using the program's tool. As you can see from the code below, it creates a mask for each region and uses it to quantify the image. It does this three times! Not at all what I wanted nor what the documentation states the function is to do. I need to pass the function a labeled mask but I do not know how to create one.
**********
'Creates a new, empty region of interest.
Dim roi As New Roi()'Creates a new RectangleContour using the given values.
Dim vaRect As New RectangleContour(73, 62, 158, 244)roi.Add(vaRect)
'Quantify
Using imageMask As New VisionImage(ImageType.U8, 7)
'Creates the mask based on the region of interest.
Algorithms.RoiToMask(imageMask, roi, new PixelValue(255), image)'Calculates statistical parameters on an image.
vaQuantifyReport = Algorithms.Quantify(image, imageMask)
End Using
roi.Dispose()
'Creates a new, empty region of interest.
Dim roi2 As New Roi()'Creates a new RectangleContour using the given values.
Dim vaRect2 As New RectangleContour(393, 288, 289, 240)roi2.Add(vaRect2)
'Quantify
Using imageMask As New VisionImage(ImageType.U8, 7)
'Creates the mask based on the region of interest.
Algorithms.RoiToMask(imageMask, roi2, New PixelValue(255), image)'Calculates statistical parameters on an image.
vaQuantifyReport2 = Algorithms.Quantify(image, imageMask)
End Using
roi2.Dispose()
'Creates a new, empty region of interest.
Dim roi3 As New Roi()'Creates a new RectangleContour using the given values.
Dim vaRect3 As New RectangleContour(816, 420, 291, 292)roi3.Add(vaRect3)
'Quantify
Using imageMask As New VisionImage(ImageType.U8, 7)
'Creates the mask based on the region of interest.
Algorithms.RoiToMask(imageMask, roi3, new PixelValue(255), image)'Calculates statistical parameters on an image.
vaQuantifyReport3 = Algorithms.Quantify(image, imageMask)
End Using
roi3.Dispose()
02-15-2010 09:34 AM
Hi Steverino,
What happened when you used the example I mentioned? We can start there to create a mask. Then you can pass that mask to Quantify (sorry for the large image) You can find this manual at <Program Files>\National Instruments\Vision\Documentation\cwimaq.chm:
Cheers,
02-15-2010 09:35 AM
When you get to this page in the manual you will see there are links to "RegionsToMask" Method and "Label" Method at the bottom of the page - you can see this in my image above.
Cheers,
02-16-2010 10:28 AM
Thanks for all your help. Got it to work. Only caveat is the regions cannot be over-lapping or I get flaky results.
Private Sub btnButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnButton1.Click
Dim imgMask As New VisionImage
Dim reportQuantify As New QuantifyReport
'ensure an image exists and has regions defined
Algorithms.RoiToMask(imgMask, imageViewer.Roi, New PixelValue(255), imageViewer.Image)
Algorithms.Label(imgMask, imgMask)
reportQuantify = Algorithms.Quantify(imageViewer.Image, imgMask)
End Sub
02-17-2010 01:48 PM