MATLAB: How to load a 3D volume image file (.vol extension) into MATLAB, edit individual 2D slices and save it back as a 3D image

.vol files3d imagesct scanimage analysisimage processingtomographyvoxel

I have a .vol extension 3D image file (an x-ray tomogram of my experimental setup). Its dimensions are x=555, y=556, z=500 i.e. 500 slices. I want to load this file into MATLAB and do the following: remove some slices from the top and bottom and then set the outer voxels (at a distance greater than a fixed distance, r) of the remaining slices to black. Then I want to save this modified volume as a 3D image of the same extension. How can I do this? If someone can help me with just how to load the .vol file and access individual slices, it would be a big help. Any help would be appreciated, thanks in advance.

Best Answer

From your information about the size of the volume and from the number of bytes in the file it would appear that it just contains the raw pixels encoded as 16-bit integers with absolutely nothing else, in particular, no information on the order of dimensions. A little bit of experimentation will be needed
fid = fopen('scan1.vol');
voxels = fread(fid, '*uint16'); %read as 16 bit unsigned. I'm assuming they're unsigned
fclose(fid);
voxels = reshape(voxels, [555, 556, 500]); %you may need to permute the numbers here
%and you may need to permute the dimensions afterward