How to open .raw files in Matlab

Hi everybody, I have a 3D image stored in a .raw format, 32 bits floating point, uncompressed. The dimensions are 288x288x400. How can I open this image in Matlab?
Thanks in advance, Joaquim Costa

1 Comment

Hi, I am also trying to import an image in .raw format. My question is that, how did you know the dimensions and other details of your image?

Sign in to comment.

 Accepted Answer

Jan
Jan on 30 Nov 2016
Edited: Jan on 1 Dec 2016
fid = fopen(FileName, 'r);
if fid == -1
error('Cannot open file: %s', FileName);
end
data = fread(fid, 288*288*400, 'float32');
fclose(fid);
data = reshape(data, [288, 288, 400]);

5 Comments

Note that it might turn out that the data is in a different order in the file so you might need to change the order of the sizes and you might need to permute().
It is especially common for rows and columns to be exchanged compared to the order MATLAB expects.
I notice that. I had to use first the flipud() and then rot90() to obtain the direction I want. How can I use permute to do the same?
How are you doing the displaying? After you display, is get(gca, 'YDir' set to normal or reverse?
@Joaquim: How do you apply flipud on a 3D-array? Please post you code instead of describing it.
R2014a redefines flipud, fliplr, rot90 to be able to handle arrays with multiple dimensions.

Sign in to comment.

More Answers (0)

Asked:

on 30 Nov 2016

Commented:

on 31 May 2018

Community Treasure Hunt

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

Start Hunting!