Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

how to save grayscale image?

I have a float array. I am doing array to image conversion and am able to display grayscale image. (using IMAQ)
I am not able to save this format using 'Image Write file2' since it supports only U8 U16.
Conversion from float to U8 or U16 compromises the output quality.
Do anyone have idea about how to save grayscale image ?
 
Thank you
 
 
0 Kudos
Message 1 of 6
(8,129 Views)
Hi NI_7,
which is the highest value in your array? I think grayscale is U8.

Mike
0 Kudos
Message 2 of 6
(8,128 Views)

Hi Mike,

I have array of float values. Max value in array is 7.68.

 I am converting that in to grayscale(SGL) image using IMAQ arraytoimage.

Thanks,

 

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

It depends on what you want to do with the file after you've saved it.  If you want to maintain the "pixel values" from your float array, you can write out a binary file that contains the single- or double-precision float data.  There is a write binary file function that will work for this. 

If you want to be able to open the image in a graphics program then you will need to convert the image to either 8-bit or 16-bit integer data.  Then decide whether you can live with a lossy compression (such as JPEG).  If you can not live with any alteration of the image data, and you want to keep 16-bits per pixel, TIFF is a format that can support that.  There is a IMAQ Write File 2 vi for that.  (Select the TIFF format from the polymorphic VI).

Here in our lab we use a binary file format (of our own design) with an ASCII header and multiple images after the header.  The header describes the image width, height, type (e.g. uint8, uint16, float32), big or little endian, grayscale or color, and so on. Anyone can open the file (with notepad for example) to figure out what is in the file.  We have a reader VI that parses the header and knows how to read the pixel data.

We also have a plugin for ImageJ (freeware) that can parse the file and read in the image sequence. 

 

Message 4 of 6
(8,122 Views)

Ok, I got it by converting them into 8-bit interger.

 

Thank you very much 🙂

0 Kudos
Message 5 of 6
(8,113 Views)

Hi,

You can use IMAQ Write File from vi.lib\vision\Files1.llb instead of IMAQ Write File 2. This vi supported AIPD format (proprietary NI image file format), which is able to save float image. You can read this image after that with IMAQ Read File. This is easiest way to save float point image:

best regards,
Andrey

Message 6 of 6
(8,112 Views)