Reading a 16 bit RAW image from Grasshopper3 (Point Grey Research)
5 views (last 30 days)
Show older comments
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146869/image.jpeg)
Thank You.
1 Comment
Guillaume
on 22 Jan 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
Answers (3)
Guillaume
on 21 Jan 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 Comments
Image Analyst
on 22 Jan 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.
Image Analyst
on 20 Jan 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 Comments
Image Analyst
on 21 Jan 2015
Well, what can I say? Just extract/crop out the stuff you need and throw away the stuff you don't need.
Witek Jachimczyk
on 21 Jan 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
0 Comments
See Also
Categories
Find more on Point Grey Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!