Main Content

Display Volume Using Cinematic Rendering

Cinematic rendering is an advanced 3-D visualization technique that simulates realistic lighting and shadows. Cinematic rendering can improve the aesthetic of a display, and makes it easier for viewers to visually perceive depths and the relative position of objects in a scene. Cinematic rendering is particularly popular for displaying 3-D medical image volumes, because visual perception is important for accurate diagnosis and planning.

Side-by-side comparison of a chest CT scan displayed using standard volume rendering and cinematic rendering

Download Image Volume Data

This example uses a subset of the Medical Segmentation Decathlon data set [1]. 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)

The folder dataFolder contains the downloaded and unzipped data.

dataFolder = fullfile(filepath,"MedicalVolumeNIfTIData");

Specify the filenames of the volume and label images used in this example.

dataFile = fullfile(dataFolder,"lung_043.nii.gz");
labelDataFile = fullfile(dataFolder,"LabelData","lung_043.nii.gz");

Import Image Volume

Read the image data and the metadata from the image file.

V = niftiread(dataFile);
info = niftiinfo(dataFile);

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];

tform = affinetform3d(A);

Define a transparency map and colormap for this volume. The values used in this example have been determined using manual trial and error.

alpha = [0 0 0.7 0.9];
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);

Display Volume

Create a viewer window in which to display the volume.

viewer = viewer3d(BackgroundColor="black",BackgroundGradient="off");

Display the volume using the CinematicRendering rendering style. Cinematic rendering applies iterative postprocessing to realistically model the diffuse light source in the scene. The default number of iterations is 100. Changing the style to cinematic rendering also automatically applies denoising to the viewer display.

vol = volshow(V, ...
    Parent=viewer, ...
    RenderingStyle="CinematicRendering", ...
    Transformation=tform, ...
    Colormap=colormap, ...
    Alphamap=alphamap);

Adjust Display Settings

You can further refine the cinematic rendering display by adjusting volume and viewer properties.

For the viewer, you can adjust properties related to denoising and the size of the light source in the scene.

  • Denoising Controls whether denoising is applied to the scene. Specifying the cinematic rendering style automatically sets the Denoising property to on.

  • DenoisingDegreeOfSmoothing Controls the strength of denoising.

  • DenoisingSigma Controls the size of the smoothing kernel.

  • Lights.Size Controls the size of the Light object stored in the Lights property of the viewer. The size of the light source affects the softness of the shadows in the scene. For this example, decrease the size of the light to make the shadows visually sharper.

Create a viewer and set the denoising parameters and light size.

viewerAdj = viewer3d(BackgroundColor="black",BackgroundGradient="off", ...
    Denoising="on",DenoisingDegreeofSmoothing=0.1,DenoisingSigma=2);

viewerAdj.Lights.Size = 0.05;

For the volume, you can adjust the number of iterations and the specular reflectance.

  • CinematicNumIterations During each iteration, the viewer samples a ray of light from the light source. A greater number of iterations generally models a real-world light source more realistically, but increases rendering times.

  • SpecularReflectance Controls the amount of light reflected off the surface. A value close to 0 makes the volume appear less shiny. A value closer to 1 makes the volume appear more shiny. The default value is 0.4. For this example, increase the value to make the ribcage appear shinier.

Display the volume in the viewer viewerAdj, and set the number of iterations and reflectance.

volAdj = volshow(V, ...
    Parent=viewerAdj, ...
    RenderingStyle="CinematicRendering", ...
    Transformation=tform, ...
    Colormap=colormap, ...
    Alphamap=alphamap, ...
    CinematicNumIterations = 100, ...
    SpecularReflectance = 0.7);

Optionally, you can clean up the viewer window by using the 3-D Scissors tool to remove the patient bed. For an example, see Remove Objects from Volume Display Using 3-D Scissors. This image shows the final volume after bed removal.

Volume display after removing the CT bed using 3-D scissors

References

[1] 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.

See Also

| |

Related Topics