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

조회 수: 12 (최근 30일)
Waqar Younas
Waqar Younas 2014년 12월 28일
댓글: Peter Camilleri 2022년 5월 6일
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!

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 28일
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
mark menesses
mark menesses 2019년 6월 11일
편집: mark menesses 2019년 6월 12일
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 2022년 5월 6일
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')

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

Community Treasure Hunt

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

Start Hunting!

Translated by