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

조회 수: 6 (최근 30일)
Mathews John
Mathews John 2015년 1월 20일
댓글: Guillaume 2015년 1월 22일
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
Guillaume
Guillaume 2015년 1월 22일
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

댓글을 달려면 로그인하십시오.

답변 (3개)

Guillaume
Guillaume 2015년 1월 21일
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
Image Analyst
Image Analyst 2015년 1월 22일
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.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2015년 1월 20일
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
Image Analyst
Image Analyst 2015년 1월 21일
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 2015년 1월 21일
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 :)

댓글을 달려면 로그인하십시오.


Witek Jachimczyk
Witek Jachimczyk 2015년 1월 21일
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