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 Using Default Volume Rendering

Create a viewer window in which to display the volume.

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

Display the volume using the default VolumeRendering rendering style. Specify the camera zoom level to focus on the rib cage.

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

viewer.CameraZoom = 1.5;

Figure contains an object of type images.ui.graphics3d.viewer3d.

Display Volume Using Cinematic Rendering

Change the rendering style to cinematic rendering. Cinematic rendering applies iterative postprocessing to more 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.RenderingStyle="CinematicRendering";

Figure contains an object of type images.ui.graphics3d.viewer3d.

Pause to apply all postprocessing iterations before updating the display in Live Editor.

pause(4)
drawnow

Adjust Display Settings

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

You can adjust the number of iterations. 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. For this example, keep the default value.

vol.CinematicNumIterations = 100;

The specular reflectance of the volume 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.

vol.SpecularReflectance = 0.7;

Specifying the cinematic rendering style automatically applies denoising to the viewer by setting the Denoising property to on. You can refine the kernel size and strength of the denoising using the DenoisingDegreeOfSmoothing and DenoisingSigma viewer properties. For this example, keep the default denoising settings.

viewer.Denoising = "on";
viewer.DenoisingDegreeOfSmoothing = 0.1;
viewer.DenoisingSigma = 2;

The size of the light source affects the softness of the shadows in the scene. Change the size by specifying the Size property of the light source, which is defined in the Lights property of the viewer. For this example, decrease the size of the light to make the shadows visually sharper.

viewer.Lights.Size = 0.05;

Figure contains an object of type images.ui.graphics3d.viewer3d.

Pause to apply all postprocessing iterations before updating the display in Live Editor.

pause(4)
drawnow

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