LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write 16 bit images into AVI file

The IMAQ AVI Write Frame VI doesn't make me very happy. It only allows 8bit or RGB images to be written/compressed. I need to acquire + store very large (many Gigabytes) image sequences at a depth of 12 bit or more. I might store uncompressed data, but frankly I would prefer some (lossless) compression.

* Is there any support (in the future?) from NI for image depths > 8 bit ?
* Are there any other (commercial) AVI-libraries around that I could access from LabView ?
* Truncating my images to 8 bits is NOT an option - I need the 12 bit information !

Thanks for any suggestions HU
0 Kudos
Message 1 of 33
(9,422 Views)
Hello HU,

the AVI file format only supports 8 bit or RGB (24 bit). This is no "NI thing". It could be that in future there are in-between stages of resolution.

Kai Kratt
National Instruments
Message 2 of 33
(9,369 Views)
Hello Kai,

(1) Many thanks for the prompt response, disappointing though it is ... 😞

(2) I do not particularly insist on AVI - it just happens to be the only "multiple image" format supported by IMAQ-Vision. Perhaps somebody can suggest to me a suitable other format (third party library ?) that can help me achieve the following:

** store approx. 200.000 pairs of VGA-resolution 16(12)bit images in one single file along with a little auxiliary information (shutter speed, time of day etc.) for each single image.

** of course some lossless compression would be nice

After a little investigation, it seems to me that multipage-TIFF could do the job. Does anybody have a better idea ?

thanks again HU
0 Kudos
Message 3 of 33
(9,362 Views)
When you say 16 bit, do you mean 16 bit per channel (so its 48bit for all 3 channels-RGB) ?
If so, you need tiff. However, window can only display 24bit image (8bit each channel).
If 16bit is for all channels, then you can convert to 24 bit, and still use AVI.

George Zou
http://gtoolbox.yeah.net
George Zou
0 Kudos
Message 4 of 33
(9,355 Views)
Did you figure out a good way to save a series of 16 bit images to a single file? I would like to do a similar thing and ran in to the same problem. Ideally, I'd like to use multipage tiff files, but I haven't found a way to implement this.
-Nick
0 Kudos
Message 5 of 33
(9,103 Views)
Hello Nick!

As of right now NI IMAQ and NI VISION do not support multi-page TIFF files.  The only single file multi image type that is supported is AVI.  My suggestion would be to convert your images to RGB, so you do not lose any data, and save them as AVI files.  The other option would be to group the images into an array and write the data out as a binary file.  I hope this helps.  Thanks and have a great day.

Regards,
Mark T
Applications Engineer
National Instruments
0 Kudos
Message 6 of 33
(9,079 Views)

Hi !

Like almost everyone here, I'm want to save 16bits images into an AVI file (witch seems the quickest format to save a live feed for several seconds or minutes). It makes sense to me to use the RGB format (witch allows the use of 24bits) to avoid loosing data, but I'm not sure how you make this conversion...

If using imaqCast, the help file clearly said that when converting IMAQ_IMAGE_I16 to IMAQ_IMAGE_RGB : "if the source value is greater than 255, the function sets each color component to 255".

The other way I can figure out is to use imaqReplaceColorPlanes to manually fill the RGB values with the LSB and MSB of the 16bits image values and then use imaqExractColorPlanes when reading back the file... with all the arithmetic and logical operations that will be needed to accomplish this.

Did I miss something or I really need to manipulate each color plane manually ?

Thank you !

David St-Arneault

0 Kudos
Message 7 of 33
(8,923 Views)
Hi David,

It is possible to use multiple color planes to store a 16 bit monochrome image. When doing this, the 8 bits of the green plane and 8 bits of the blue plane would be used. This would result in an AVI that is only blue and green in color. If you are using the AVI to store the images and read them back at a later time, this might work for you. However, if you plan to view the AVI as a file, I wouldn't recommend this method. In addition, the process of converting the image to 32 bits can be time consuming (depending on image size), so the speed of acquisition and AVI frame writing would decrease.

The process involves 3 steps:
1) Convert the image to an array of signed 16 bit integers (IMAQ ImageToArray)
2) Cast the array to unsigned 32 bits (To Unsigned Long Integer)
3) Convert the unsigned 32 bit array to an RGB(U32) image (IMAQ ArrayToColorImage).

Once the final RGB(U32) image is created, you can write the AVI frame. When reading the AVI frames back in, you would need to use the inverse of the above steps (IMAQ ColorImageToArray, To Signed Integer, and IMAQArrayToImage).

Hope this helps!
Message 8 of 33
(8,884 Views)
Thank you Michael,

This is very clear and more simple than I expected.

I will try this and see if it is fast enough.

David
0 Kudos
Message 9 of 33
(8,880 Views)
Hi Michael (or anyone else),

Since I have Vision 7.1.1, I don't have the
IMAQ ArrayToColorImage or IMAQ ColorImageToArray functions.

To save my 16 bits avi file and read them back, I use the following code :

    Write :               
                               errChkVISION(imaqDispose(AVIlongArray));         // Dispose previous image
                               AVIlongArray = (unsigned long int *)imaqImageToArray(ImaqLiveFeedImage, IMAQ_NO_RECT , &numCols , &numRows );
                               errChkVISION(imaqArrayToImage(ImaqAVIColorImage,AVIlongArray,numCols, numRows));
                               errChkVISION(imaqWriteAVIFrame(ImaqAVIColorImage,AVI,"data_to_write",13));

    Read :
                               errChkVISION(imaqReadAVIFrame(ImaqAVIColorImage, AVI, AVIframe, NULL, NULL));
                               AVIshortArray = (short *)imaqImageToArray(ImaqAVIColorImage,IMAQ_NO_RECT ,&numCols,&numRows);
                               errChkVISION(imaqArrayToImage(ImaqLiveFeedImage,AVIshortArray,numCols,numRows));
                               errChkVISION(imaqDispose(AVIshortArray));   

It seems to work very well if I write one avi file and read it back.

But... if I write several avi files one after the other, only the first one is ok. For every other AVI, there is vertical black lines added to the images (see attachments).

My application is build in C++ with visual studio 2005. I use a backgroundworker to do the image acquisition and write the avi. The "DoWork" method is called for each avi I want to save. After each acquisition, I dispose every buffers,close the avi file, stop the acquisition then close the interface and session. I reinitialize everything before doing another acquisition.

While doing the acquisition, I display the images and write the avi file. The displayed images are correct.

Any idea about where the black lines come from ?

Thank you !

David


Download All
0 Kudos
Message 10 of 33
(8,815 Views)