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 Photorealistic Volume Using Cinematic Rendering
This example uses a subset of the Medical Segmentation Decathlon data set . The subset of data includes two CT chest volumes and corresponding label images, stored in the NIfTI file format.
Run this code to download the
MedicalVolumNIfTIData.zip file from the MathWorks® website, then unzip the file. The size of the data file is approximately 76 MB.
zipFile = matlab.internal.examples.downloadSupportFile("medical", ... "MedicalVolumeNIfTIData.zip"); filepath = fileparts(zipFile); unzip(zipFile,filepath)
dataFolder contains the downloaded and unzipped data.
dataFolder = fullfile(filepath,"MedicalVolumeNIfTIData");
Specify the filenames of the volume and label image used in this example.
dataFile = fullfile(dataFolder,"lung_043.nii.gz"); labelDataFile = fullfile(dataFolder,"LabelData","lung_043.nii.gz");
Read the image data and the metadata from the image file.
V = niftiread(dataFile); info = niftiinfo(dataFile);
Define a transparency map and color map for this volume. The values used in this example were determined using manual trial and error.
alpha = [0 0 0.7 1.0]; color = [0 0 0; 200 140 75; 231 208 141; 255 255 255] ./ 255; intensity = [-3024 -700 -400 3071]; queryPoints = linspace(min(intensity),max(intensity),256); alphamap = interp1(intensity,alpha,queryPoints)'; colormap = interp1(intensity,color,queryPoints);
This MRI scan has a nonuniform, or anisotropic, voxel size. Extract the voxel spacing from the file metadata, and define the transformation to display the volume with correct dimensions.
voxelSize = info.PixelDimensions; sx = voxelSize(2); sy= voxelSize(1); sz = voxelSize(3); 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 as a 3-D object. Specify the rendering style as
"CinematicRendering". The cinematic rendering style displays the volume based on the specified color and transparency for each voxel,with iterative postprocessing that produces photorealistic shadows and lighting.
viewer = viewer3d; vol = volshow(V,Parent=viewer, ... RenderingStyle="CinematicRendering", ... Colormap=colormap, ... Alphamap=alphamap, ... Transformation=tform);
Pause to apply all postprocessing iterations before updating the display in Live Editor.
 Medical Segmentation Decathlon. "Lung." Tasks. Accessed May 10, 2018. http://medicaldecathlon.com/. The Medical Segmentation Decathlon data set is provided under the CC-BY-SA 4.0 license. All warranties and representations are disclaimed. See the license for details.
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
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 volume based on the specified color and transparency for each voxel, with iterative postprocessing that produces photorealistic shadows and lighting.
This rendering style is useful for displaying opaque volumes.
View the volume using a volumetric light scattering model that simulates the absorption, inscattering, and outscattering of light through the volume.
This rendering style is useful for displaying translucent volumes that do not have large intensity gradients, such as smoke, fog, and clouds.
|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
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
R2023b: Cinematic rendering, volumetric light scattering, and specular reflectance
Volume object has
new properties, and options for existing properties, to control the specular reflectance of
the volume and display a volume using cinematic rendering or volumetric light scattering. To
set any of these property values at object creation, specify them to the
volshow function as name-value arguments.
Control the amount of light reflected by a volume using the new
SpecularReflectanceproperty. Increase the specular reflectance to make a volume appear shinier.
"CinematicRendering"to display a photorealistic volume using iterative postprocessing. Specify the number of postprocessing iterations using the new
"LightScattering"to display the volume with volumetric light scattering, including light absorption, inscattering, and outscattering. Specify the balance between rendering quality and speed using the new
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.
- Display Volume Using Cinematic Rendering
- Display Interior Labels by Clipping Volume Planes
- Display Interior Labels by Adjusting Volume Overlay Properties
- Remove Objects from Volume Display Using 3-D Scissors
- Display Large 3-D Images Using Blocked Volume Visualization
- Display Translucent Volume with Advanced Light Scattering