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:
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 :)
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'?
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.
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
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.
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.