Main Content

Display Interior Labels by Adjusting Volume Overlay Properties

This example shows how to reveal labels on the interior of a labeled volumetric image by adjusting the transparency of the volume.

By default, the volshow function renders the exterior of a volume as opaque. This visualization is not very informative when there are labels inside of the volume. To see the labels inside the volume, you can increase the transparency of the volume or change the rendering style. Using these approaches, you can see the interior labels and still recognize the details of the exterior surface of the volume. Update display settings using name-value arguments of the volshow function, which set properties of the output Volume object. For a complete list, see Volume Properties.

For an example that shows how to view interior labels using clipping planes, see Display Interior Labels by Clipping Volume Planes.

Load Data

Load a volumetric image and corresponding labels. The volume has three classes and a background label, 0.

dataDir = fullfile(toolboxdir("images"),"imdata","BrainMRILabeled");
load(fullfile(dataDir,"images","vol_001.mat"));
load(fullfile(dataDir,"labels","label_001.mat"));

Display Discrete Labels with Label Overlay Rendering

Create a viewer window by using the viewer3d function. To illustrate the effect of individual display parameters, this example creates several viewers. For your own code, to avoid memory errors, limit the number of viewers you create in a given MATLAB session.

By default, the viewer has a blue background. You can zoom in on the volume by specifying the CameraZoom name-value argument.

viewer = viewer3d(CameraZoom=2);

Display the volume with the labels as an overlay. The volume appears opaque with the default visualization settings. When you have labeled data, the default value of the OverlayRenderingStyle property is "LabelOverlay". This value is appropriate when the labels are discrete, such as these labels.

volshow(vol,Parent=viewer, ...
    OverlayData=label);

Apply Gradient Opacity Rendering Style to Volume

To distinguish the labels, display the volume viewers with a white background.

viewerLabels = viewer3d(BackgroundColor="white",BackgroundGradient="off",CameraZoom=2);

Change the rendering style of the volume by specifying the RenderingStyle name-value argument as "GradientOpacity". The gradient opacity rendering style applies a localized transparency when adjacent voxels have similar intensities. The effect is that regions in the volume with uniform intensity appear more transparent, while voxels that have large gradients in intensity around them appear more opaque. This rendering style is particularly helpful when you want to view inside of a volume while still visualizing the defining features of the volume. You can adjust the strength of the gradient opacity effect using the GradientOpacityValue property.

volshow(vol,Parent=viewerLabels, ...
    RenderingStyle="GradientOpacity", ... % Change volume rendering style
    OverlayData=label);

Adjust Volume and Label Transparency

The labels inside the volume are now visible, but they are still hard to distinguish from the rest of the volume. Make the volume data more transparent by decreasing the Alphamap property. You can also increase the opacity of the labels by increasing the OverlayAlpha property. The OverlayAlpha property is useful when you want to view all labels with the same transparency, and hide zero-value label pixels corresponding to background.

viewerLabels2 = viewer3d(BackgroundColor="white",BackgroundGradient="off",CameraZoom=2);

volshow(vol,Parent=viewerLabels2, ...
    RenderingStyle="GradientOpacity", ...
    Alphamap=linspace(0,0.2,256), ... % Decrease volume opacity
    OverlayData=label, ...
    OverlayAlpha=0.8); % Increase label opacity

Only two labels are easily visible. The third label in yellow is mostly hidden within the orange and purple labels, and only a few voxels of yellow are visible on the surface. You can hide individual labels by adjusting the OverlayAlphamap name-value argument, which specifies a custom alphamap. First, create an custom alphamap alpha that is a 256-element vector of zeroes. Then, set the third element, corresponding to the orange label, to 0.8. Finally, specify the OverlayAlphamap property as the custom alphamap alpha.

viewerLabels3 = viewer3d(BackgroundColor="white",BackgroundGradient="off",CameraZoom=2);

alpha = zeros(256,1);
alpha(3) = 0.8;

volshow(vol,Parent=viewerLabels3, ...
    RenderingStyle="GradientOpacity", ...
    Alphamap=linspace(0,0.2,256), ...
    OverlayData=label, ...
    OverlayAlphamap=alpha); % Specify custom label alphamap

Display Continuous Labels with Gradient Overlay Rendering

Instead of discrete labels, suppose you want to overlay continuous data over the volume. Continuous data could be statistical voxel measurements such as heatmaps and activation maps, or image data from other imaging modalities. In this case, suitable values for the OverlayRenderingStyle are "VolumeOverlay" and "GradientOverlay".

Load another image modality and overlay it with the original volume data using the "GradientOverlay" overlay rendering style. Specify the OverlayColormap as the continuous turbo colormap, which is suitable for displaying heatmap overlays. The default colormap is suitable for displaying discrete label regions. Specify the OverlayDisplayRangeMode to limit the display range to the data range of the data.

vol2 = load(fullfile(dataDir,"images","vol_003.mat"));
vol2 = vol2.vol;

viewerContinuous = viewer3d(BackgroundColor="white",BackgroundGradient="off",CameraZoom=2);

volshow(vol,Parent=viewerContinuous, ...
    RenderingStyle="GradientOpacity", ...
    Alphamap=linspace(0,0.2,256), ...
    OverlayData=vol2, ...
    OverlayRenderingStyle="GradientOverlay", ...
    OverlayColormap=turbo(256), ...
    OverlayDisplayRangeMode="data-range");

Increase the visibility of the interior labels by decreasing the values of the OverlayAlphamap property.

viewerContinuous2 = viewer3d(BackgroundColor="white",BackgroundGradient="off",CameraZoom=2);

volshow(vol,Parent=viewerContinuous2, ...
    RenderingStyle="GradientOpacity", ...
    Alphamap=linspace(0,0.2,256), ...
    OverlayData=vol2, ...
    OverlayRenderingStyle="GradientOverlay", ...
    OverlayColormap=turbo(256), ...
    OverlayDisplayRangeMode="data-range", ...
    OverlayAlphamap=linspace(0,0.5,256)); % Decrease label opacity

See Also

|

Related Topics