open a 24-bit depth interleaved RGB RAW file

Using fread, how do i open a RAW file? which is of size m*n*3 ?
i realise a lot of questions have been asked already but no clear answer exists.

Answers (2)

No clear answer exists because RAW format is different for each manufacturer (and possibly different between models as well.)

4 Comments

I'm assuming that's because header files differ on each manufacturer's raw file. But if I have an image without the header file, how do I open it?
Nevertheless, I used Fread and managed. Thank you.
@pooja: "raw" files are not uniquely defined and it is not only restricted to the header. The values could be stored in column or row order, or by keeping the 3rd dimension together. Even 8x8x3 blocks are possible and more efficient for some calculations. The values can be stored in integer or floating point format, with the most significant bytes at first or at last. Summary, same has Walter has posted already: Any manufacturer can and does use its own format. Without further information, only a statistical analysis or a comparison with the original picture provided in well defined format can reveal the way, the data are stored.
No, RAW files can have any internal structure that the manufacturer wants. It is not necessarily a simple rectangular array of pixel values with a header before it. The readings for each individual sensor might be included, but in most cameras there is not one physical sensor for each R, G, B: some of the sensors are shared between adjacent pixels, and that could be stored in the file in arbitrary ways.
.RAW is any private internal format that the manufacturer cares to use.
The RAW file that i have is that of a colour image that contains values in RGBRGBRGB... form. without any headers.
If i have to open a grayscale image,
i could probably use
fid=fopen(filename,'r') image=fread(fid,[width,height], 'uint8') fclose
but i don't know how to open a colour image.

Sign in to comment.

Try this:
rgbImage = fread(fileHandle, [x_size, y_size, 3], '*uint8');
Does that work? If not, try reading it in as 1D and then extract
rgbImage = fread(fileHandle, (x_size * y_size * 3), '*uint8');
redChannel = reshape(rgbImage(1:3:end), [y_size, x_size]);
greenChannel = reshape(rgbImage(2:3:end), [y_size, x_size]);
blueChannel = reshape(rgbImage(3:3:end), [y_size, x_size]);
rgbImage = cat(3, redChannel, greenChannel, blueChannel);

2 Comments

If the pattern is RGBRGBRGB then you need to fread() [3, x_size, y_size], and then permute() [2 3 1]
However, if the image is row-scanned instead of column-scanned, then fread() [3, y_size, x_size) and permute() [3 2 1]
Thanks for clarifying that. If they followed the BMP style, the data would be stored BGRBGRBGR..... So if the colors don't look right, then try swapping the red and blue channels.

Sign in to comment.

Asked:

on 11 Sep 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!