Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a labeled image mask (VB 2005)?

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!

0 Kudos
Message 1 of 8
(4,390 Views)

Do you have vision assistant. You can simply choose multiple regions like this.

 

mult.JPG

0 Kudos
Message 2 of 8
(4,386 Views)

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.

Message Edited by Michelle_B on 02-12-2010 11:57 AM
--Michelle

National Instruments
0 Kudos
Message 3 of 8
(4,376 Views)

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()

 

 

0 Kudos
Message 4 of 8
(4,367 Views)

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:

2010-02-15_093203.png

 

 

Cheers,

--Michelle

National Instruments
0 Kudos
Message 5 of 8
(4,339 Views)

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,

--Michelle

National Instruments
0 Kudos
Message 6 of 8
(4,338 Views)

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

0 Kudos
Message 7 of 8
(4,317 Views)
Yes, I believe overlapping will give you an invalid ROI and, thus, an invalid Mask. You should be able to combine overlapping ROIs into a single ROI and turn that into a mask. You can do this within LabVIEW with a VI called Group ROIs. I'm trying to find the corresponding function for VB.

Is this something you are interested in doing, or is it alright if you ensure all ROIs do not overlap?

Cheers,
--Michelle

National Instruments
0 Kudos
Message 8 of 8
(4,301 Views)