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

44 views (last 30 days)
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.
  1 Comment
Guillaume
Guillaume on 28 Jan 2020
As far as I know there is no standard .vol format. In any case, that's not something that matlab knows how to handle.
Possibly your .vol file is the same format as in this answer so you could try the code there. If not, it may be the format described here, it would be easy to write a decoder for that, but possibly it's a proprietary format for which you'd need the documentation from the vendor of your software.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 29 Jan 2020
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
  5 Comments
Hege
Hege on 5 Aug 2020
Hi, I am also using this script.but I am getting reshape error. Appreciate your comments
fid = fopen('F:\REICOFIL\reicofil_D_7mm_6um_1d42s_01\reicofil_D_7mm_6um_1d42s.vol');
voxels = fread(fid, '*uint16'); %read as 16 bit unsigned. I'm assuming they're unsigned
fclose(fid);
voxels = reshape(voxels, [1920, 1920, 1536]); %you may need to permute the numbers here
% %and you may need to permute the dimensions afterward
Error-vol
Error using reshape
To RESHAPE the number of elements must not change.
Error in vol (line 4)
voxels = reshape(voxels, [1920, 1920, 1536]); %you may need to permute the numbers here

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!