Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Thresholding of image is not working

Hi All,

 

I am using Visual Studio 2008, Measurement studio 2010 and NI Vision Development Module 2010 Service Pack 1 (SP1) . I wrote a C# code to threshold my image. When I write the following C# code, irrespective of whatever ThresholdMethod I use, I get a black image. Can you please let me know what is wrong?? I have also attached the image that I want to segment.

 

VisionImage mVisionImage = new VisionImage();

mVisionImage.ReadFile(@"C:\Development\Test Code and Experiments\NI Vision\Images\Lids low light good focus and Lighting.bmp");   imageViewer1.Attach(mVisionImage);

VisionImage result = new VisionImage();

Algorithms.AutoThreshold(mVisionImage, result,  2, ThresholdMethod.Clustering );

imageViewer1.Attach(result);

 

Thanks,

 

Venkat

0 Kudos
Message 1 of 8
(3,191 Views)

Hello Rham

 

Can you please take a look at your image as array data?  I suspect what might be happening is that your image may actually be thresholding but only as 0s and 1s as values out of 255.  Can you please do an image to array function to see what your actual black image data looks like?  Is it all 0s? 

 

Thank you very much!

Sincerely,

Greg S.
0 Kudos
Message 2 of 8
(3,182 Views)

Hi Greg S,

 

Thanks for the reply. I wrote the following code 

 

        PixelValue2D arrayData = result.ImageToArray();          

int nonZeroPixelsCount = 0;

        int zeroPixelsCount = 0;

        foreach (byte b in arrayData.U8) {

if (b != 0) {

++nonZeroPixelsCount;

} else {

++zeroPixelsCount;

}

}

 

As you had mentioned, I see that there are 1's and 0's. I believe that the image is being thresholded. Now, I want to see what is the resultant image from the thresholding and find out what are the areas of the image that are captured. How do I go about doing it?

 

Also, I am a very new to programming in Computer Vision and NI Vision. As I had mentioned in my previous mail, I am trying to use NI Vision from C#.NET. The only documentation I see for the Vision .NET libraries and classes I need to use is the Measurement Studio menu in Visual Studio. I find them useful but however, I feel that I need more documentation, help and insight. Can you please tell me where I can find them?

0 Kudos
Message 3 of 8
(3,178 Views)

Hello Rham

 

Which image forward are you using?  For example if you are using 8-bit grayscale and you wish to see the resultant image, multiply each invidual term in the image matrix by 255 so that all the 0s remain 0 but all the 1s become maximum luminance.  Then you should be able to see what you are looking for.

 

In terms of text based support for NI Vision products, please look for the examples under Start >> National Instruments >> Vision >> Text-Based.

 

Thank you very much!

Sincerely,

Greg S.
0 Kudos
Message 4 of 8
(3,173 Views)

Hi Greg S.,

 

Thanks for the reply. I did that and the thresholding seems to be working. Is it possible for me to set my own thresholding values, say I want my interest points to be set to 255 instead of 1 and the background to 0.

 

Also, can you please tell me what automatic thresholding works best to locate the circles in the image that I had shared in my first post. This is because, all of the automatic thresholdings I tried does not seem to work best for my problem. Is this the right forum to address this question?

 

Thanks,

 

Venkat

0 Kudos
Message 5 of 8
(3,166 Views)

Hi,

 

I was wondering if anyone had an opportunity to look at this.

 

Thanks,

 

Venkat

0 Kudos
Message 6 of 8
(3,154 Views)

Rham,

 

Have you tried using the Background Correction threshold function?  See attached result...

 

Robert Eastlund
Graftek Imaging, Inc.
Phone: (512) 416-1099 x101
Email: eastlund@graftek.com
0 Kudos
Message 7 of 8
(3,144 Views)

Hello Rham

 

An easy way around this issue is to just multiply the individual elements of your matrix by 255.  Any value that was 0 remains 0 and any value that was 1 is now 255.

 

Yes this is the right forum, can you please tell me about the different methods you have tried?

 

Thanks again!

Sincerely,

Greg S.
0 Kudos
Message 8 of 8
(3,141 Views)