Reading a 16 bit RAW image from Grasshopper3 (Point Grey Research)

6 visualizaciones (últimos 30 días)
Mathews John
Mathews John el 20 de En. de 2015
Comentada: Guillaume el 22 de En. de 2015
Hi,
I have been trying to read a 16 bit RAW image, captured using a Grasshopper3 Camera (Point Grey Research), in MATLAB. All images were captured using the Flycapture2 software. The image itself is 1384x1036 and has a memory stride of 2768 (since it's a 16 bit image). After a lot of reading in various parts of the web, I figured that RAW images are supposed to be considered as a binary stream of data. So with the following code i should be able to read the RAW image:
row = 1036; col = 1384;
fin = fopen('raw13.raw','r');
ima = fread(fin, [col*2 row],'uint8');
temp = zeros(col,row);
j=1;
for i=1:2:col*2-1
temp(j,:) = ima(i,:) + ima(i+1,:)*2^8; %The first element is the lower 8bits and the second element is the higher 8bits
j = j+1;
end
imshow(temp',[0 2^16-1])
This is not creating the image I want and there seems to be a lot of overlap and a lot of data missing in the reconstructed image. A I don't think I am doing anything wrong. Is there anyway of knowing what the exact size of the RAW file would be and does anyone else have previous experience with this camera? Would be helpful if someone could help with the file format.
Thank You.
  1 comentario
Guillaume
Guillaume el 22 de En. de 2015
So, from your comment, the problem is that there's a bug in the manufacturer's software and your code is fine.
I just want to point out that you could simplify it a lot by reading the image straight as uint16:
row = 1036; col = 1384;
fin = fopen('raw13.raw','r', 'l'); %'l' optional on little-endian platform (windows)
ima = fread(fin, [col row], '*uint16'); %read as uint16 and store as uint16
fclose(fin);
imshow(fin); %because ima is uint16, you don't need to specify the range

Iniciar sesión para comentar.

Respuestas (3)

Guillaume
Guillaume el 21 de En. de 2015
I've been able to read RAW images successfully using multibandread. Now, one RAW image format is different from another RAW image format, so there's no guarantee it will work for you, but give it a try.
However, are you sure that the image is truly 16 bits. A quick search on the web, would indicate your camera is either 12 or 14 bits. In which case, it's possible that reading as 16 bits is wrong. Possibly try:
img = multibandread('filename', [1036 1384 1], 'ubit12=>uint16', 'bsq', 'ieee-be')
Ultimately, you need to refer to either the software documentation or the camera documentation to know the details of their RAW format. The content of the file is supposed to be a dump of the sensor data without any processing.
  2 comentarios
Image Analyst
Image Analyst el 22 de En. de 2015
He said the manufacturer admitted that the raw files being written out in the current version are corrupt, but fortunately the pgm files are okay.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 20 de En. de 2015
Why not just save the image as a standard format like PNG? As far as I know all run of the mill machine vision cameras will let you save your images in a variety of standard formats. Are you absolutely sure raw is the ONLY format? I got some images from someone who used a Point Grey camera and they were in TIFF format.
Can you attach one of the raw images?
  8 comentarios
Image Analyst
Image Analyst el 21 de En. de 2015
Well, what can I say? Just extract/crop out the stuff you need and throw away the stuff you don't need.
Mathews John
Mathews John el 21 de En. de 2015
Hey! Thanks for all the help. I talked to tech support thoroughly. It seems the raw file produced from the version of the software I am using is um... corrupted I suppose. The code I am using was perfect and worked perfectly when I got the raw file from a previous version.
Thank You so much anyways :)

Iniciar sesión para comentar.


Witek Jachimczyk
Witek Jachimczyk el 21 de En. de 2015
Indeed, knowing the format precisely is the key. I found a little bit about it here:
but it still needs to be understood thoroughly. If it's headerless, you might be able to use vision.BinaryFileReader from the Computer Vision System toolbox:
HTH,
Witek

Community Treasure Hunt

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

Start Hunting!

Translated by