Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you write an image threshold to a file

Hi, I use IMAQ threshold to threshold an RGB image. How do I write this image to a file? Whenever I use the IMAQ Write JPG or Write PNG vI and try to view the file with the windows image viewer all I see is a black image. Does anyone know how to save a binary image?
0 Kudos
Message 1 of 8
(4,526 Views)
This makes sense since your thresholded image has pixel values of either 0 or 1. These pixel values are both interpreted as being black on a grayscale image. The solution is to change the pixel values to be 0 and 255. To do this, I would just use the IMAQ Multiply.vi and multiply the entire image by 255. This new image should appear correctly in third party viewers.

Kyle V
Message 2 of 8
(4,526 Views)
That works great! Now I have another problem. What if I have a floating point image that I want to save to a file? All of the file formats give a runtime error when i try to write the file.
0 Kudos
Message 3 of 8
(4,526 Views)
File formats, like BMP, JPEG, and TIFF, are based on pixel bit depth standards. I doubt any of these standards account for floating point pixels. Your best bet is to cast your image to a 16 bit grayscale image and save it as a TIFF file. I believe BMP and JPEG only support 8-bit grayscale images.

In general, using floating point pixels is great for image manipulation and operations, but it usually doesn't mean much to the final product. Especially when it comes to displaying an image (your computer screen only shows integer pixel values).

Hope this helps.

Kyle V
0 Kudos
Message 4 of 8
(4,526 Views)
Yeah, that makes a lot of sense. I've been trying to figure out how to cast this image and display it, but when I use IMAQ CastImage to 16bit and IMAQ SAVE TIFF and look at the image using the windows image viewer i only see black...any ideas? If i use the IMAQ Image Display to display the floating point image, it displays what i expect, i'm just having trouble casting it for the save! Thanks for all of your help.
0 Kudos
Message 5 of 8
(4,526 Views)
If you cast it to an eight bit image and save it as a BMP or JPEG does it show up correctly? If so the problem probably lies in the fact that a 16-bit image in LabVIEW is signed, while third party viewers usually assume that it is unsigned. So rather than pixel values going from -32766 to 32767, they go from 0 to 65536. There are example programs on ni.com to get around this. One is called "Mapping a 16-bit Image to an 8-bit Image," another is called "Bit Shift an IMAQ Vision 12-bit Image and Resave for External Viewer." If you search for these titles on the ni.com search bar, you should be able to find them.

Kyle V
0 Kudos
Message 6 of 8
(4,526 Views)
Thanks, i got it to work using the Mapping a 16-bit image to a 8-bit image design technique.
0 Kudos
Message 7 of 8
(4,526 Views)

hi can plz help me out.....i want to show grayscale images into Bitmap (0-7 bits). Is it possible to show garyscale image into bitmap 1 bit, 2bit,..upto...7bit image.

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