Doug's MATLAB Video Tutorials

December 11th, 2009

Advanced: Making a sweeping slice through volume of data.

A MATLAB user recently asked how we could make a visualization similar to this one.

I was a little surprised that we were able to do the visualization, with interactivity in less that 15 lines of code.

%%
d = flow; d = shiftdim(d,2);
x = 25;
y = 26;
z = 21.59561;
v =  3.22068;

h = slice(d,x,y,z)
d(:,:,z:end) = nan;
isosurface(d,-v)

set(h,'edgeColor','none')
axis equal
zlim([0 size(d,3)])
colormap spring

This video makes use of cell mode to get the interactivity. You can see how something like this could be done with a GUI to get the interactivity that you might want.

If you like this kind of thing, Slice-o-matic, will be good for you.

3 Responses to “Advanced: Making a sweeping slice through volume of data.”

  1. Vick replied on :

    Good job Doug, I wasn’t quite sure what those +- cell modes were until I saw this video. Another thing I was expecting in this code was “hold on” somewhere, I believe either slice or isosurface has it by default?

  2. Shaffy replied on :

    Hey Doug,

    I am doing something similar to your work, I’m building 3d human head using 377 image slices.
    I have wrote this following code:

    myFolder = 'C:\Users\shaffy\Desktop\Design 4\HEAD';
    head = imread([myFolder, 'a_vm1001.png']); %read first one to get sizes
    V = zeros(size(head,1),size(head,2),377,class(head));
    V(:,:,1) = head;
    for ii = 2:377 %loop through the rest
     file_name = ['a_vm1' num2str(ii,'%03i') '.png'];
     V(:,:,ii) = imread([myFolder file_name]);
    end
    

    But when I run this I get errors such as : ??? Assignment has more non-singleton rhs dimensions than
    non-singleton
    subscripts

    Can you help me?

    Thanks man

  3. dhull replied on :

    Shaffy,

    Run this with the debugger at the line that is giving your problems, run just the left hand side and the right hand side, see what is coming out. You might have to reshape, or gather the outputs or something. Hard to tell without your data.

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.