# simple 3D volume visualization

Discussion in 'MATLAB' started by Mark Mather, May 13, 2008.

1. ### Mark MatherGuest

Hello. I have looked over the volume visulization techniques
documentation and I still can't make much sense of it.

It seems the technique here is some form of:

vol3d=patch(isosurface(data,isovalue))

In the scalar data example they use mri data as the volume,
then somehow find the 'skin' on the surface all has an
isovalue of 5. This makes no sense to me, as looking at the
data this is simply not true. What exactly is an isovalue- I
seem to read it is like a contour line but from the example
the skin portion does not seem to be all the points with a
value of 5 (or lower/higher than 5).

Is there a simple clear explanation of what is going on here?

As a very simple example, take a 20x20x20 zero matrix, and
put random integers in a 5x5x5 cube in the center. How can I
plot the surface of this cube, regardless of the values? How
can I plot just a wire frame of the surface of the cube?

I have searched but never seem to find any guide on how to
do this other than the official documentation, so if someone
could point me n the right direction to do simple things to
build my technique on that would be greatly appreciated.

Mark Mather, May 13, 2008

2. ### Scott BurnsideGuest

doc surf

Scott Burnside, May 13, 2008

3. ### Mark MatherGuest

I don't have a function to define [X Y Z] for my data, they
are scalar indices of a 3D image. How would I use surf to
show this?

Mark Mather, May 13, 2008
4. ### helperGuest

As a very simple example, take a 20x20x20 zero matrix, and
Well, this isn't "regardless of the values", but it shows
an example of how to create the wire mesh you mention using
ISOSURFACE:

A = zeros(20,20,20); % 20-by-20-by-20 zeros
A(8:12,8:12,8:12) = 1; % 5-by-5-by-5 cube of 1's

h = patch(isosurface(A,.99)); % Create "contour" at 0.99

set(h,'FaceColor','none') % "Hide" faces
view(3) % Rotate to 3-D view

I'm not sure, however, what you actually want. How does
this example differ from what you actually want?

helper, May 14, 2008
5. ### Mark MatherGuest

Thanks so much, that's exactly the kind of simple example I
need to pick apart.

I changed it to this, and am now a bit confused:

A = zeros(20,20,20); % 20-by-20-by-20 zeros
B=rand(5,5,5).*10 %generate random 5-by-5 data
A(8:12,8:12,8:12) = B

h = patch(isosurface(A,7)); % Create "contour" at 7?

set(h,'FaceColor','red') % make faces red
view(3) % Rotate to 3-D view

So is this new grouping of red faces encapsulating all the
points less than 7?

I have a series of MRI slices of a head in scalar format.
Outside of the head are zero values. I would like to plot a
wire mesh around the surface of the head.

Next I would like to show the head (or a region inside the
head) in solid form, say all voxels above value 100 or
something. Obviously with hold on this will show where in
the head these regions are located and orientated.

Thanks!!!

Mark Mather, May 14, 2008
6. ### helperGuest

I don't think "encapsulating" is the right word.
ISOSURFACE interpolates the data and plots the surface
where the interpolated A data is 7. This may or may not be
closed surface based on what form the data takes. Check
out the Flow example in the documentation for ISOSURFACE.
There isn't a closed surface.

Try this:

D = squeeze(D); % Convert it to "Volume" data
h = patch(isosurface(D,.99)); % Show the 0.99 isolevel
set(h,'FaceColor','none') % Turn off all faces
view(3) % Adjust the view to 3-D.

example, the largest values (~88) all occur in the skull,
so any isolevel you plot is going to include the skull.
However, if you did have data with larger values in the
interior (e.g., over 100), you could plot these using the

hold on
h2 = patch(isosurface(D,100)); % Show the 100 isolevel

helper, May 14, 2008
7. ### Mark MatherGuest

Great! I think I finally understand- it's the transition
from 0 to anything above 1 that is showing up as the path
vertices (when set at .99).

I added a solid red rectangle to the interior as such:
D = squeeze(D); % Convert it to "Volume" data
D(60:64,60:64,16:20)=100; %make red box
h = patch(isosurface(D,0.99)); % Show the 0.99 isolevel
set(h,'FaceColor','none','EdgeColor','blue') % Turn off all
faces, make edges blue
view(3) % Adjust the view to 3-D.
h2 = patch(isosurface(D,90)); % Show the 90 isolevel
set(h2,'FaceColor','red')

So my next two questions relate to making the edges less
obtrusive- can I have it look for less vertices at a
distinct interval? I looked at the patch properties and
didn't see anything like this.

I tried

set(h,'FaceColor','none','EdgeColor','blue', EdgeAlpha, 0.5)

and it crashes matlab. I can do EdgeAlpha, 'flat' fine, so
perhaps it is my graphics setup.

Thanks so much for your help and patience with this simple
task, this really helps a lot and hopefully many others will
find it useful.

Mark Mather, May 16, 2008
8. ### helperGuest

So my next two questions relate to making the edges less

Look into the REDUCEVOLUME and SHRINKFACES functions.

Ewwwwww. It crashes my computer too. It seems to be
having a problem with the large number of faces. Using
REDUCEVOLUME with the factors [4,4,2] allows setting an
EdgeAlpha value without crashing.

I definately recommend reporting this crash directly to
technical support (not the the [email protected] email they
give). This has got to be a bug.

I didn't like how REDUCEVOLUME looked, but using
SHRINKFACES with a very small number, for example:

shrinkfaces(h,0.01)

seemed to be able to retain some decent skull resolution.

helper, May 16, 2008