LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving 12-bit *.avi files

Solved!
Go to solution

I'm looking for the fastest way of saving incoming images from a camera (>125fps). I was originally using the write .avi VI but when I tried to save 12-bit images, the VI wouldn't allow me to, saying it only supports 8-bit grayscale or 32-bit RGB. Is there any way of saving a 12 or 16-bit grayscale .avi's? If not, what is the best way of saving incomg data like this?

Thanks 

0 Kudos
Message 1 of 11
(6,681 Views)

Hi, Phoenix,

 

There are different possible ways. But unfortunately you can't write 16 bit image directly to *.avi file (at least I don't know which player will be able to play such file).

Anyway what you can do:

 

Method 1. Downscale your 12 bit image to 8 bit (with lookup table), then write 8 bit gray video file. Of course, some gray information will be lost.

 

Method 2. Split your 12 bit to 8 and 4 bit, then write 8 bit to Red channel, and 4 bit to Green channel, then write RGB video file. When you will play this file you should extract two color planes from each frame and restore 12 bit image back, then visualize it. In this case you own player needs to be developed for viewing such video.

 

Method 3. The same as method 2, but you can write two gray *.avi file. One for 8 most significant bits, and another one for 4 less significant bits. First file can be played in any AVI player. If you want to recover full 12 bit image, then you have to develop your own player, which will read both avis frame to frame and join bits.

 

Method 4. Simple write 12 bit RAW images frame to frame into single binary file. This is probably fastest and simplest way (but your hard drive should be big and fast enough for streaming images at 125 fps). Is this possible or not -  depends from the size of the images...

 

best regards,

Andrey.

 

0 Kudos
Message 2 of 11
(6,667 Views)

Or you can write to a 16 bit grayscale multipage TIFF file.

 

BTW, you can't display a 12 or 16 bit grayscale image on Windows, as OS only support 8 bit grayscale.

 

 

George Zou

http://www.geocities.com/gzou999

George Zou
0 Kudos
Message 3 of 11
(6,654 Views)

Thanks for the help guys

The data doesn't need to be veiwed fortunately. Its only a way of storing interference images before they are processed at a later point and reconstructed into an image. They do need to be as higher quality as possible so downscaling is not an option.

I had thought of using the different colour channels to store 12-bit but i don't know how to implement that idea in a Labview program, is there a VI that can combine seperate RGB channels into one image? 

The speed at which the incoming data is captured and stored is critically important and needs to be as fast as possible. If streaming binary data to a single file is the quickest way, can you send me a sample program of how to do this? 

thanks very much 

0 Kudos
Message 4 of 11
(6,634 Views)
Solution
Accepted by Phoenix729

Success!

After a few hours struggling with IMAQ replace colour plane, I discovered that IMAQ array to colour image will do it for you. All you need to do is convert the 12 (or 16) bit image into array format and then use the aforementioned VI and it will write 8 bits into the blue channel and 4-bits into the green channel. 

Thanks for the help!

0 Kudos
Message 5 of 11
(6,602 Views)

Hi,

 

Finally, I am glad that see this post. I want to acquire several 100 16bit images (12bit actually)  and save them without any loss of information. I found the IMAQ ArrayToColorImage technique too. But, I am having a problem with it. I am giving the detailed information on what I have been doing. I appreciate any help.

 

The procedure I followed is:

  1.  Grab the image and convert it into an Array using ImageToArray function
  2. Cast the array into U32 format (I am not sure if I need this step).
  3. Use the IMAQ ArrayToColorImage function to convert the RGB image and add into AVI file.
  4. I have a different program to again convert the RGB image back to an array and save them as ASCII text or dat files for subsequent analysis in MATLAB or other software.

Please see the attached VIs with the code.

 

When I do that. The program seems to be working for the first AVI file. The information is preserved between the conversion. But, the data in the second and subsequent AVI is not preserved. The pixel values are close the maximum limit of U32 format ( 4.2950e+009 etc) rather than in the range of 1 to 4096. I checked the pixel values at each step, after casting to U32 and the pixel values are presereved. Interestingly, the data from the first AVI has pixel values from 1 to 4096. 

 

When I exit from Labview and restart the program the first AVI works and the subsequent AVI files show the same problem. 

 

I further analyzed the arrays extracted from the first and the second AVI. I took data from a standard image for the first and the second AVI. When I determine the minimum pixel value and subtract the value from the all the pixels of the image, the pixel values of the two images becomes same. That is the minimum pixel value (value near 4.2950e+009) of the image from second AVI  is subtracted from other pixels and the minimum pixel value (around 250) of the image from first AVI is subtracted from respective image. Then both the images look the same. 

 

That is, somehow on subsequent AVIs the ArrayToColorImage function is converting the values differently. I am attaching the VIs. I have been trying to figure it out for a while. 

 

I appreciate any help in this matter. 

 

BTW, I contacted the NI support regarding this matter with no result. The ticket got expired before the problem is solved.

 

Thank You,

Ravi. 

Download All
0 Kudos
Message 6 of 11
(6,128 Views)

Hi

In the end i decided to ditch the .avi file saving scheme, there always seemed to be a drawback - converting to RGB avis took 4 times the hard disk space for example.

I'm currently using file to the write to binary file VI after converting the incoming image to an array of I16 numbers. This works very well for me as i can stream to the hard disk whilst keeping the overall hard disk space cost down to a minimum. Also the write to binary file VI take care of any overheads concerning image location and seperation. This makes it really easy to read the data again using read binary file VI, as it will automatically return the I16 array data in a 3 dimensional array so indexing off a specific image is no problem.

 

As you need to re process the images again before analysis, there would be no additional programs needed either

 

Would this be useful for your application?

0 Kudos
Message 7 of 11
(6,113 Views)

Hi Phoenix,

 

 Thank you for the message. I am not aware of the size issues with RGB images. My application needs the program to work continuous for hours and capture images periodically. I wanted to skip saving images regularly as I noticed writing files to hard disk is taking more time than I can spare. So, I choose this technique as AVI files can handle 100s of frames easily. I heard about binary file format and its advantages. But, I never used it. 

I appreciate if you can provide a sample code or your code so that I can check for my application. I do several projects that involve capturing multiple images in a short time and saving them to hard disk is always a problem. 

 

BTW, can we save other data formats in a binary file. 

 

Any thoughts, ideas and suggestions from your experience are welcome.

 

Thank you,

Ravi.

0 Kudos
Message 8 of 11
(6,102 Views)

Hi Ravi,

Saving in RGB format requires the data to be in U32 (32 bit) format whereas your data is in 12 bit format - but labview won't support 12 bit data so you need to use I16 (16 bits of memory) to read the data from the data aquisition hardware. Hence saving as U32 takes more space then is necessary as the other 16bits of memory space (U32-I16=I16) are wasted. Which also explains why your minimum pixel value was 4.2950e+009 !

 

Definitely give binary file writing a go, its just as easy as writing to AVIs as they are both methods of streaming data to the hard drive. Just rewrite the code to save to a binary file, either one or many different files using indexed naming. Alternatively you could pass data out of your acquisition loop and into a saving loop, maybe by using queues or something similar. Check the labview examples for queue function basics. 

 

I can post an example of using queues in data aquisition and saving tomorrow 

 

If you're having problems with file saving due to the size of the files you could look into setting up a RAID. This would instantly give you a 2x increase in file saving speed

0 Kudos
Message 9 of 11
(6,085 Views)

Hi,

 

Thank you for the reply. I hope you had a nice weekend. I also thought about saving files in binary image format. But, I never used it. Can you please post an example that shows saving sequence of images as a binary file. I have a question, can we save a sequence of images (3D image data) as a single binary file. One more doubt I have is, we have to read the binary files later using Labview to convert them ascii files or other files easy to handle. 

 

BTW, did you try reading the binary file created in Labview using MATLAB or other software. 

 

Thanks a lot,

Ravi.

0 Kudos
Message 10 of 11
(6,062 Views)