Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Save image in a RAW file format

Hello All;
 
I can use IMAQ ReadFile to read in images with a RAW file format... the question is, how can I save an image to a RAW file format?
 
The saving to a RAW file is a requirement for a project I am currently working on, which is why saving to other formats (such as TIF, BMP, etc., which I also use in this application) is critical.
 
Please advise.  Thanks in advance!
 
DJH
0 Kudos
Message 1 of 7
(7,228 Views)
Hi DJH,
 
There is no single definition of a "RAW" file format. That format is in reference to the .RAW files that some higher-end digital cameras can save to instead of JPEG/TIFF/etc. In this mode the camera generally writes out the raw contents of the sensor and other data that would then be processed by the camera and converted into the final image. Typically this is much more data than ultimately gets condensed into the final image. The data is typically not bayer-decoded and is in a higher bit-depth than JPEG. This allows greater range of offline post-processing than is available when the image has been already been processed by the camera.
 
However, every camera manufacturer typically has a different format of the data written to the file. Applications that can open "RAW" formats typically have support for several common company's formats, but generally you use a utility provided by the camera manufacturer to manipulate the RAW image into something more usable. I suppose you could find a definition of some company's simplest RAW format available and try a binary file like that, but I'm not sure I see the point, unless it is simply to store higher bit-depth data than JPEG allows. However, you can always store 16-bit TIFF images and get the same end result.
 
 
-Eric
0 Kudos
Message 2 of 7
(7,223 Views)

OK, thanks;

I have since got most of my "save image to raw" working, for the specific raw format I am looking for.  Essentially, I dump the image into a 1D array, and write to a binary file, specifying little endian byte order.  However, I am getting an incorrect result.

I have attached a screenshot of my code... here are my steps:

(1) Convert image to 2D array using IMAQ ImageToArray and I16 to U16 conversion;

(2) Reshape 2D array into a consecutive 1D array;

(3) Write 1D array to a binary file, using little endian byte format.

Essentially, this is working, except that the two "halves" of my image are switched... i.e. columns 0-2047 are where 2048-4095 are supposed to be, and vice versa!  (see "Split Image Display.bmp; I have included "Proper Image Display.bmp" to show the correct image... observe the horizontal sliders to see where the switch actually takes place).

The image I am trying to convert and save is a 16-bit, 4095x2048 image.

I have troubleshooted the array conversion, and it seems to be working correctly... i.e. row1=0-4095, row2=4096-8191, row3=8192-12287, and so on.

Is there anything obvious I am doing incorrectly?  Is there a possible issue with how I am writing to binary file?

Any help would be appreciated!  Thanks in advance!

DJH

0 Kudos
Message 3 of 7
(7,208 Views)
OK; I figured out the problem... as is the case with most problems incurred on a Friday evening, a restful weekend and a clear head on Monday morning does wonders...
 
(1) The reshape array from the 2D output (IMAQ ImageToArray) to the 1D input (Write to Binary File) really isn't needed... the Write to Binary File appears to take care of this already.  I'm not sure if the Write to Binary File VI inserts carriage returns at the end of each array row or not (perhaps someone would be kind enough to answer that), but it seems fine.  I'll likely leave this in anyway, as it doesn't hurt to be extra cautious.
 
(2) The bulk of the problem was how I was reading the RAW file.  In our application, we have a DPX image file, which is essentially a RAW file with a 4K header.  Turns out, I was treating the RAW the same as my DPX, stripping off the 4K header, which in turn caused the screwup with my image.  Fix the read method, fix the problem.
 
Hopefully, this bit of info will be of use to someone else.
 
DJH
0 Kudos
Message 4 of 7
(7,179 Views)
Hey DJH,

I'm working on something similar and your method could be of help to me.

I'd really appreciate it if you could attach your finished, and working VI portion from the previous post?

0 Kudos
Message 5 of 7
(7,160 Views)

Absolutely!

Please see attached for the IMQ - Save Image to File.vi;

Insofar as reading in the RAW file, here are the settings I use (these match the Save VI):

!RAW Image Setup
Image Type=Grayscale (I16)
Image Size X=4096
Image Size Y=2048

!RAW File Options
Read Raw File=Read Raw File
File Data Type=16 bits (unsigned)
Offset to Data=0
Use Min Max=Don't use min max
Optional Min Value=0
Optional Max Value=0
Byte Order=Little endian (Intel)

Hope this helps!

DJH

0 Kudos
Message 6 of 7
(7,136 Views)
RAW is defined by camera, usually linear if it is straight off the GiGe pipe or you can configure a LUT for log profile. Most use linear and post processing with LUT.
0 Kudos
Message 7 of 7
(7,038 Views)