File Exchange

image thumbnail

4D Volume Visualization

version (8.49 KB) by Joshua Stough
4D (3D+1) volume visualization with windowing, custom colormaps, and component selection


Updated 23 Apr 2013

View License

A tool for visualizing vector-valued volumetric data, which has become more common recently in medical imaging (e.g., 3D + time, multi-modal acquisition). The function accepts a 4D matrix, allowing the user to interactively select the 4th dimensional component to display. The 3D volume for the particular component is shown in a neurological coordinate frame with three orthogonal planar views along with a built-in 'slice' visualization. The user may also supply a cell array of colormaps, which populate a menu within the gui.

Comments and Ratings (13)


A one liner alternative to Cecil's bug fix error from 6 Jun :

line 365, replace:
whichView = find(cell2mat(handles) == gca);

whichView = find(cellfun(@(x) x == gca,handles));

Also for the other errors related to str2num, just find and replace every one of them to str2double.

Cecil Yen

I also fixed a bug in the 4D slider, which has one extra step.
I changed line 200 to
set(dimensionSlider, 'Min', 1, 'Max', sI(4), 'SliderStep', [1/(sI(4)-1) 1/(sI(4)-1)]);

Cecil Yen

Here is a dirty fix for the error below:
I replaced the cell2mat function on line 384 with
if handles{1} == gca
whichView = 1;
elseif handles{2} == gca
whichView = 2;
elseif handles{3} == gca
whichView = 3;
whichView = 4;

I also replaced flipdim function with flip function as recommended by Matlab 2018a.

Cecil Yen

It doesn't work well with the newer Matlab version from 2017a to 2018a.

1st error can be fixed by replacing str2num to str2double
Input must be a character vector or string scalar.
Error in vis4d/switchComponent (line 692)
set(gca, 'XTickLabel', flippedx(str2num(myx)));
Error while evaluating UIControl Callback.

I have don't have a quick fix for the 2nd error.
CELL2MAT does not support cell arrays containing cell arrays or objects.
Error in vis4d/buttonDownCallback (line 384)

bh dhouha

hi, this is great but does notvisualize a complete volume like a whole plain cylinder, a complete sphere etc..., does it?

simple and useful, thanks. perfect for the non experts like me

Guy Wilson

Response to John:
Thank you for your question John. Your question concerned why certain slicing of your data seem to appear in the wrong orthoplanes. While I am slightly chagrined, the honest response is that I have intentionally permuted and flipdim'd to make my particular data (MRI images in analyze75 format) appear as I want it (RAS). Search for 'permute' and 'flipdim' in the code to customize it for yourself.
As an aside, the particular examples you provide disagree with your own description. For example, Aq(c,:,:,f) is not plotting the xz plane, it's actually the yz plane (all y and all z for a particular x).


Hi Joshua,
thanks for your software. I have found it very useful.
I wondered if you would be able to explain something to me. If I plot Aq(constant,:,:,frame), I am plotting the xz plane. When I visualize it with your software, I see this cut in the yz plane. (similar occurrence with Aq(:,constant,:,frame, this time the yz cut appears in xz.) Is there any reason for this, or have I misunderstood something?


Response to Gustavo: My code doesn't care how you got the image. If it, say 'I', exists in matlab as a 4d array of any class (use size and class functions to determine this), then just try 'vis4d(double(I));' instead of whatever you were doing.

For loading nifti images, exchange #8797 seems popular:

Good luck,


Hi. I have started working with you toolboxes but i can't get any results. I have NIFTI images to work with. How can i adapt them to your toolbox?

Thanks in advance

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: 3D Volume Visualization

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor