An update to Joe Conti's popular vol3d function, allowing voxel colors and alpha values to be defined explicitly. Functionality is increased, but the function is entirely backwards compatible.
In cases where voxels can be any RGB color, use:
where cdata is an MxNxPx3 array, with RGB color along the 4th dimension. In cases where color and alpha values are highly independent, specify an MxNxP alphamatte as follows:
vol3d('CData', cdata, 'Alpha', alpha);
This function amends the original (as little as possible) with the full permission of Joe Conti. The original function comes with some additional tools for editing colormaps and alphamaps which are not included in this version. See:
But pls can you give me a little example...am a beginner but I want to apply this to a chemical Engineering problem
C = 2.4:2.4:28.8%gotten from the function
Pls how will the rendering thing be applied
Great tool for volume rendering. Many thanks.
Excellent!But I don't want the blue colour when the values in the matrix are Zeros. How to change the zero values into transparency.
Very nice tool, exactly what I want, to see the sulcus and gyri. However, there are big differences after 2014a. Seems like the images getting pixelized. And in 2014a and before, sometimes it appears artificial lines on the rendering. Could u give some hint ?
I'm looking for a way to minimize GPU memory usage when rendering rather large 3D image stacks with vol3D. This is a neat script but for "2D texture" mode I'm not sure how Matlab sends new image slices added to a plot to GPU: Is it as plain 2D GPU textures, or some other format including extra overhead? Also what format is used, I guess it involves conversion from double to some fixed point format, right?
nice job pal...can you please provide me some report or presentation to understand the code. actually i have a very short time and have to submit a report. can you please help me in that...shall be grateful to you :)
nice tool but the performance is not good as other medical visualization tools :(.
In my case, the locations were converted to Cartesian coordinate from Polar coordinate using this code:
phi = ([1:300]/299)*2*pi;
r = [1:2000];
h = [0:9];
[PHI,R,H] = meshgrid(phi,r,h);
x = R.*cos(PHI);
y = R.*sin(PHI);
z = H.*0.3;
How can I specify the location (x,y,z) of my cData?
When i use the command
i get a plot with complete blue colour.
I don't want the blue colour when the values in the matrix are Zeros.
I want 'White' colour, when the values are exactly Zeros.
How to change the colour 'Blue' to 'White'?
Hi Oliver, nice visualization tool! Was wondering which is the best way to add labels on the axes? By using xlabel/ylabel/zlabel, the labels aren't displayed, especially if one rotates the 3d volume.
Wow! It has just made an almost impossible job very easy. Thanks! I will certainly be inspecting this code to learn a thing or two :)
Oliver, this is really brilliant!
I have another question. Is it possible to include interpolation while carrying out the 3D rendering if there is a certain element spacing between each slice?
An excellent contribution for 3D rendering. However, the initial vol3d is not available anymore.
Absolutely wonderful code. Very useful for visualizing voxel representations of part models for analysis of casting properties.
I made a slight change to the code on my own machine that has made some models a bit prettier. Specifically, at lines 204, 222, and 239, (drawing individual surface patches for x,y,z slices), I added a second line that adds 1 to the relevant dimension to draw the back surface of each voxel as well. While this obviously doubles the quantity of objects that need to be rendered, it makes very thin voxel sections (1 voxel thickness) more aesthetically appealing.
Perhaps an option to draw back surface patches? Just a suggestion.
Thank you for this code, I wouldn't be moving nearly as fast on my own work without it.
Naomi - The help text clearly states:
vol3d(...,'XData',x) 1x2 x-axis bounds. Default: [0 size(data, 2)].
vol3d(...,'YData',y) 1x2 y-axis bounds. Default: [0 size(data, 1)].
vol3d(...,'ZData',z) 1x2 z-axis bounds. Default: [0 size(data, 3)].
I have nothing more to add.
How can I specify the location (x,y,z) of my cData?
Great 3D visualization tool.
Excellent tool, works well for 3D probability density functions. Thanks.
Oliver, it is possible to use vol3d for 3D map ? I have 3D data (latitude x longitude x time). I want to produce a volumetric plot, how to use vol3d for this ?
Oliver, Thank you so much, it works fine with me
Mohamed: If you run the demo you should discover that mri.mat is included with MATLAB. The 3D data is displayed using textured-mapped 2D planes, as described in the help. Call
to see a 3D view of the data.
Hello oliver, I used your code to display a 3D volume raw data, using this command "H= vol3d('cdata',datafile); it just displayed the 2D images on top of each other, looks like only a one 2d image, the datafile format is (x,y,z), where x is the number of frames, y *z is the 2d image's size, also at the end of the module, you load a mat file "mri.mat" which is not included, could you please advise me with that? thank you so much, you reply is highly appreciated
This script works great to display MRI-like 3d images.
In the case that I have a logical 3d array (ie: a segmentation mask of an anatomical structure from an MRI), how can I use vold3d to only show the resulting mask? I am able to display my MRI model, but when I just want to display the mask I get a blank plot.
I = a [MxNxP] matrix for my MRI [grayscale values 0-255]
J = a [MxNxP] matrix for my mask [logical 0 or 1]
vol3d('cdata',I, 'texture','3D'); %this works
vol3d('cdata',J, 'texture','3D'); %this is blank
Thank you for your help.
The hgsave command works, many thanks
Wilson: saveas requires a figure handle. vol3d returns a structure, hence the first error. The second error is due to the figure being too large. Try:
hgsave(gcf, 'Image3D.fig', '-v7.3');
Nice code, but in my case, I can only render a 3D image but can not save the image.
When I use command:
h = vol3d('CData',Y); saveas(h,'Image3D.fig');
Matlab displays it's a 'Invalid handle'
If I save the image directly from figure, it displays:
Warning: Variable 'hgS_070000' cannot be saved to a MAT-file
whose version is older than 7.3.
To save this variable, use the -v7.3 switch.
> In hgsave at 93
In general\private\saveasfig at 7
In saveas at 126
In filemenufcn>localSaveExportHelper at 203
In filemenufcn>localSaveExport at 316
In filemenufcn at 56
And only a figure frame is saved instead of the actual image.
The rendering method does stress MATLAB's rendering pipeline, so large volumes can slow down your machine significantly. Good graphics hardware helps a bit. Smaller datasets do too.
matlab collapses if i run vol3d code
Matthias: The latest version allows you to set axis limits.
Matthias: Unfortunately specifying different axis values isn't currently possible using this function. It is straightforward to implement though. You just need to change lines 121, 124 and 127 to achieve the desired results.
Wonderful script to generate 3D Volume plots.
However I need to set the axis values other than just the sizes of the data matrix.
How can one specifiy the axis (in x,y and z) for this plot?
Marvelous! Gorgeous 3d renderings of MRIs. Esp. in bone colormap.
Avoid destroying other vol3d objects when rerendering. Added a demo.