vol = volshow(
Volume object that displays the 3-D volume
V. You can rotate and zoom in and out on the display interactively
using the mouse. Use
vol to query and modify properties of the
Volume object after you create the object. For a list of properties,
see Volume Properties.
modifies the appearance of the volume using one or more name-value arguments. For example,
vol = volshow(
volshow(V,RenderingStyle="Isosurface") displays the 3-D volume
V and sets the rendering style as
Blocked Image Volume
bVol = volshow(
BlockedVolume object that displays the 3-D blocked image
bim. You can rotate and zoom in and out on the display
interactively using the mouse. Use
bVol to query and modify
properties of the
BlockedVolume object after you create the object. For a
list of properties, see BlockedVolume Properties.
modifies the appearance of the blocked volume using one or more name-value arguments. For
bVol = volshow(
ResolutionLevel="coarse" specifies the resolution level to
display as the coarsest resolution level.
Medical Imaging Toolbox™ extends the functionality of the
(Image Processing Toolbox™) function to display a
medicalVolume (Medical Imaging Toolbox) object in the patient coordinate system. For more
volshow (Medical Imaging Toolbox).
Visualize Volume of MRI Data
Load MRI data into the workspace and remove the singleton dimension.
load mri V = squeeze(D);
Generate a colormap and transparency (alpha) map suitable for MRI images.
intensity = [0 20 40 120 220 1024]; alpha = [0 0 0.15 0.3 0.38 0.5]; color = [0 0 0; 43 0 0; 103 37 20; 199 155 97; 216 213 201; 255 255 255]/255; queryPoints = linspace(min(intensity),max(intensity),256); alphamap = interp1(intensity,alpha,queryPoints)'; colormap = interp1(intensity,color,queryPoints);
This MRI scan has a non-uniform, or anisotropic, voxel size of 1-by-1-by-2.5 mm. Specify the transformation matrix that scales the image to the correct voxel dimensions.
sx = 1; sy= 1; sz = 2.5; A = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1];
affinetform3d object that performs the scaling.
tform = affinetform3d(A);
View the volume with the custom colormap, transparency map, and transformation. Drag the mouse to rotate the volume. Use the scroll wheel to zoom in and out of the volume.
vol = volshow(V,Colormap=colormap,Alphamap=alphamap,Transformation=tform);
Visualize Volume of CT Data
This example uses 3-D volumetric human chest CT scan data. To run this example, you must download the sample data from MathWorks® using the Add-On Explorer. See Install Sample Data Using Add-On Explorer.
Load the data into the workspace.
Create a colormap and transparency map suited for CT images.
intensity = [-3024,-16.45,641.38,3071]; alpha = [0, 0, 0.72, 0.72]; color = [0 0 0; 186 65 77; 231 208 141; 255 255 255]/255; queryPoints = linspace(min(intensity),max(intensity),256); alphamap = interp1(intensity,alpha,queryPoints)'; colormap = interp1(intensity,color,queryPoints);
View the volume with the custom colormap and transparency map. Drag the mouse to rotate the volume. Use the scroll wheel to zoom in and out of the volume.
vol = volshow(V,Colormap=colormap,Alphamap=alphamap);
Programatically set the camera position and camera target of the scene to see a different view of the volume.
scene = vol.Parent; scene.CameraPosition = [275 75 140]; scene.CameraTarget = [256 256 160]; scene.CameraUpVector = [0 0 1];
Create Animation of Rotating Volume
Load a grayscale volume into the workspace and display the volume using
load("spiralVol.mat") h = volshow(spiralVol); viewer = h.Parent; hFig = viewer.Parent; drawnow
Specify the name of the GIF file in which to save the animation.
filename = "animatedSpiral.gif";
Aim the camera at the center of the volume.
sz = size(spiralVol); center = sz/2 + 0.5; viewer.CameraTarget = center;
Specify the number of frames in the animation, then create an array of camera positions in a circle around the center of the volume.
numberOfFrames = 12; vec = linspace(0,2*pi,numberOfFrames)'; dist = sqrt(sz(1)^2 + sz(2)^2 + sz(3)^2); myPosition = center + ([cos(vec) sin(vec) ones(size(vec))]*dist);
At each camera position, update the display and write the frame to the GIF file. You can play the file in a video viewer.
for idx = 1:length(vec) % Update the current view viewer.CameraPosition = myPosition(idx,:); % Capture the image using the getframe function I = getframe(hFig); [indI,cm] = rgb2ind(I.cdata,256); % Write the frame to the GIF file if idx==1 % Do nothing. The first frame displays only the viewer, not the % volume. elseif idx == 2 imwrite(indI,cm,filename,"gif",Loopcount=inf,DelayTime=0) else imwrite(indI,cm,filename,"gif",WriteMode="append",DelayTime=0) end end
Visualize Blocked Image Volume
This example creates a large 500-by-500-by-2500 image volume. If your machine does not have enough memory to create and store the 2.5 GB volume, decrease
imSize before running this example.
imSize = [500,500,2500];
Create a simulated 3-D image of bubbles,
V. This can take several minutes.
V = rand(imSize,"single"); BW = false(size(V)); BW(V < 0.000001) = true; V = bwdist(BW); V(V <= 20) = 1; V(V > 20) = 0;
If you try to display
volshow returns an error that the volume is too large. Instead, create a
blockedImage object that points to
V and has a block size of 500-by-500-by-500 voxels.
bim = blockedImage(V,BlockSize=[500,500,500]);
volshow function reads blocks into memory one at a time and stitches individual block renderings to produce the final volume.
bVol = volshow(bim);
V — 3-D volume
3-D volume, specified as a numeric array.
config — Rendering information
Rendering information exported by Volume Viewer, specified as a structure.
bim — Blocked image volume
Blocked image volume, specified as a
object that reads 3-D blocks of grayscale, RGB, or RGBA data. The blocked image can have
a single resolution level or multiple resolution levels.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
volshow(V,RenderingStyle="Isosurface") displays the 3-D
V and sets the rendering style as
The properties listed here are only a subset. For a full list of in-memory volume properties, see Volume Properties. For a full list of blocked volume properties, see BlockedVolume Properties.
Parent — Parent
Parent of the
specified as a
Viewer3D object. You can create a
function. When you call
volshow without specifying a parent, the
function creates a new
Viewer3D object and sets that object as the
BlockedVolume object cannot be
RenderingStyle — Rendering style
"VolumeRendering" (default) |
Rendering style, specified as one of the values in the table.
|View the volume based on the specified color and transparency for each voxel.|
|View the voxel with the largest intensity value for each ray projected through the data. For RGB volumes, view the voxel with the largest luminance in the CIE 1976 L*a*b* color space.|
|View the voxel with the smallest intensity value for each ray projected through the data. For RGB volumes, view the voxel with the smallest luminance in the CIE 1976 L*a*b* color space.|
View the volume based on the specified color and transparency with an additional transparency applied if the voxel is similar in intensity (for grayscale volumes) or luminance (for RGB volumes) to the previous voxel along the viewing ray.
When a volume with uniform intensity is
View an isosurface of the volume specified by the value in the
View three orthogonal slice planes.
Alphamap — Transparency map for volume content
linspace(0,1,256)' (default) | n-element column vector
Transparency map for the volume content, specified as an
n-element column vector with values in the range [0, 1]. The
maximum length of the vector is 256. When viewing RGB volumes, the object uses the
luminance of the voxel in the CIE 1976 L*a*b* color space to assign a transparency
from the transparency map. When the
AlphaData property is nonempty, the
Alphamap property has no effect.
Colormap — Colormap
gray(256) (default) | n-by-3 numeric matrix
Colormap of grayscale volume data, specified as an n-by-3 numeric matrix with values in the range [0, 1]. The maximum number of colors n is 256. This property has no effect when viewing RGB volumes.
OverlayData — Overlay data
 (default) | numeric array |
Overlay data to blend with the object data during rendering, specified as one of these values:
The viewer shows the overlay only when the
RenderingStyle property value is
"GradientOpacity". You can modify the appearance of the overlay
by changing the
OverlayRenderingStyle — Overlay rendering style
"LabelOverlay" (default) |
Overlay rendering style, specified as one of the values in the table.
View the overlay based on the color and transparency of each labeled region. Use this rendering style to visualize ordinal data, like binary or semantic segmentation results, on top of your data.
View the overlay based on the specified color and transparency for each voxel.
View the overlay based on the color and transparency for each voxel with an additional transparency applied based on the difference between the current voxel and the previous voxel along the viewing ray.
vol — Volume
Volume, returned as a
Volume object. For more information about
modifying aspects of the volume, see Volume Properties.
bVol — Blocked Volume
Blocked volume, returned as a
BlockedVolume object. For more
information about modifying aspects of the volume, see BlockedVolume Properties.
To receive notification from a
BlockedVolume object when
certain events happen, set up listeners for these events. You can
specify a callback function that executes when one of these events occurs. When the object
notifies your application through the listener, it returns data specific to the event. Look
at the event class for the specific event to see what is returned.
|Event Name||Trigger||Event Data||Event Attributes|
An object clipping plane is being interactively moved. This event does not execute if the clipping plane is programmatically moved.
|An object clipping plane stops being interactively moved. This event does not execute if the clipping plane is programmatically moved.|
An object slice plane is being interactively moved. This event does not execute if the slice plane is programmatically moved.
|An object slice plane stops being interactively moved. This event does not execute if the slice plane is programmatically moved.|
Version HistoryIntroduced in R2018b
R2023a: Display blocked images
volshow function now supports displaying large image volumes
stored as a
object. When you pass a
blockedImage object as input,
volshow displays the volume and creates a
BlockedVolume object. The
properties control the appearance and behavior of the blocked image volume within a 3-D
scene. For a list of these properties, see BlockedVolume Properties.
volshow function now returns a
instead of a
volshow object. The
Volume object offers more
rendering styles and integrates with a
Viewer3D object to offer easier
control of the volume visualization. The
Volume object also supports web
volshow function accepts a different set of name-value
arguments based on the properties of the
Volume object. For a list of these
properties, see Volume Properties.
When you call
volshow without specifying a parent object, the
function now creates a new
Viewer3D object and sets that object as the
parent. Before, the function identified the current figure using the
gcf function and set that figure as the parent.
If you want to reproduce the prior behavior, then use the
images.compatibility.volshow.R2022a.volshow function to create a
volshow object. Note that the
images.compatibility.volshow.R2022a.volshow function and the
volshow object will be removed in a future release.
Viewer | Volume Properties | BlockedVolume Properties |