From: Puruhito Prakosa on
My problem is in dealing with creating an image from a mask file (raw image). I successfully read the image data from a 181x217x181 file (image is 181x217, with 181 slices) using fopen and fread; this dumps the values into a large 1 dimensional vector. My question is how to reshape the data back into its 181x217x181 form? Each time i run my program using reshape it always ended up with error.

Here is my program code:

[FileName, PathName] = uigetfile({'*.*', 'All Files (*.*)'}, 'Choose image to load..');
if isequal (FileName, 0)
disp('Image is loaded..')
else
disp(['Loaded image: ', fullfile(PathName, FileName)])
end

image = fullfile(PathName, FileName);
getImage = fopen(image, 'rb');
im = fread(getImage, inf, 'uchar');
fclose(getImage);
im = reshape(im, 181, 217, 181);
im = mat2gray(im);
im = im';

Can anyone help?