How do I open .raw files in MATLAB? and binarise these greyscale images?

24 views (last 30 days)
I am new to MATLAB and am trying to use image processing to analyse high speed shots of a droplet falling in air. Firstly I need to binarise these images in .raw format then analyse two images and work out the droplet sizes and centre of gravities along with the distance they have travelled. I don't have any idea how to do this and am failing to open the .raw files after viewing some youtube videos.
any help will be greatly appreciated!

Answers (1)

Image Analyst
Image Analyst on 28 Dec 2014
You need to know the format of the raw files. Is it just all the pixel values line by line with no header information at all? Or is there some header in there? Can you find out? Can you attach one?
  5 Comments
mark menesses
mark menesses on 11 Jun 2019
Edited: mark menesses on 12 Jun 2019
This comment comes some years after the original question, but I'm hoping it can help others in the future. This is what I did to open RAW files produced from a Photron high speed camera.
The RAW file saved by the Photron software (tested with PFV 3.6) saves the images a little differently depending on whether it is monochrome or color (I think). I had a color image I was trying to convert and was able to do so using the code below. Hope it helps!
% Open file and go to beginning
fid=fopen('filename.raw','r');
fseek(fid,0,'bof')
% Read all contents with 8 bit precision and store as uint8
all_contents=fread(fid,'ubit8=>uint8');
% If you're image is monochrome, I think you should be able to reshape it and be done.
% Mine is color, so I had to break it up like so.
R=all_contents([1:3:end-2]);
G=all_contents([2:3:end-1]);
B=all_contents([3:3:end]);
% Transposing each individually and then combining
R=R';
G=G';
B=B';
I=cat(3,R,G,B);
Peter Camilleri
Peter Camilleri on 6 May 2022
This worked great!
I used this as a base to convert the raw image to png. All that was added was image height and width which were used to resize the arrays. I could could then write the the file as a png.
% Open file and go to beginning
fid=fopen('filename.raw','r');
fseek(fid,0,'bof')
H = 320; W = 240;
% Read all contents with 8 bit precision and store as uint8
all_contents=fread(fid,'ubit8=>uint8');
% If you're image is monochrome, I think you should be able to reshape it and be done.
% Mine is color, so I had to break it up like so.
B=reshape(all_contents([1:3:end-2]),W,H);
G=reshape(all_contents([2:3:end-1]),W,H);
R=reshape(all_contents([3:3:end]),W,H);
% Transposing each individually and then combining
R=R';
G=G';
B=B';
I=cat(3,R,G,B);
imwrite(I,'filename.png')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!