Display Labeled Medical Image Volume in Patient Coordinates
This example shows how to display labeled 3-D medical image volumes by using the
volshow function. You can visualize labels as an overlay by using the
OverlayData property of the
Volume object created by
volshow. Additionally, you can use the spatial referencing information from a
medicalVolume object to transform intrinsic image coordinates, in voxel units, to patient coordinates in real-world units such as millimeters.
Download Image Volume Data
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. 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 = fullfile(filepath,"MedicalVolumeNIfTIData");
Specify the filenames of one CT volume and its label image.
dataFile = fullfile(dataFolder,"lung_043.nii.gz"); labelDataFile = fullfile(dataFolder,"LabelData","lung_043.nii.gz");
Import Image Volume
Create a medical volume object that contains the image data and spatial referencing information for the CT volume. The
Voxels property contains a numeric array of the voxel intensities. The
VoxelSpacing property indicates that the voxels are anisotropic, with a size of 0.7695-by-0.7695-by-2.5 mm.
medVolData = medicalVolume(dataFile)
medVolData = medicalVolume with properties: Voxels: [512×512×129 single] VolumeGeometry: [1×1 medicalref3d] SpatialUnits: "mm" Orientation: "transverse" VoxelSpacing: [0.7695 0.7695 2.5000] NormalVector: [0 0 -1] NumCoronalSlices: 512 NumSagittalSlices: 512 NumTransverseSlices: 129 PlaneMapping: ["sagittal" "coronal" "transverse"] Modality: "unknown" WindowCenters: 0 WindowWidths: 0
VolumeGeometry property of a medical volume object contains a
medicalref3d object that specifies the spatial referencing information. Extract the
medicalref3d object for the CT scan.
R = medVolData.VolumeGeometry;
Calculate the transformation that maps between the intrinsic and patient coordinate systems by using the
intrinsicToWorldMapping object function. The function returns an
tform = intrinsicToWorldMapping(R);
Import Label Data
Create a medical volume object that contains the label image data. The label image has the same spatial information as the intensity CT volume.
medvolLabels = medicalVolume(labelDataFile);
Display CT Volume with Tumor Overlay
Create a colormap and transparency map to display the rib cage. The
color values are based on the CT-bone rendering style from the Medical Image Labeler app. The
intensity values for this volume have been tuned using trial and error.
alpha = [0, 0, 0.72, 0.72]; color = ([0 0 0; 186 65 77; 231 208 141; 255 255 255]) ./ 255; intensity = [-3024 -200 0 3071]; queryPoints = linspace(min(intensity),max(intensity),256); alphamap = interp1(intensity,alpha,queryPoints)'; colormap = interp1(intensity,color,queryPoints);
View the CT volume with the custom colormap and transparency map. The
volshow function creates a
vol. Specify the
Transformation property of
tform to include the spatial referencing information and plot the image in patient coordinates. Drag the cursor to rotate the volume. Use the scroll wheel to zoom in and out of the volume.
vol = volshow(medVolData.Voxels, ... Colormap=colormap, ... Alphamap=alphamap, ... Transformation=tform);
Programatically set the camera position and camera target of the scene to view the volume in the coronal anatomical plane. You can also set the view interactively by clicking the Y orientation marker in the figure window.
scene = vol.Parent; scene.CameraPosition = [-4.0999 314.9362 -143.0000]; scene.CameraTarget = [-4.0999 -6.9636 -143.0000];
View the tumor label image as an overlay on the CT volume. You can set the
OverlayAlphamap properties of an existing
Volume object, or specify them during creation using
vol.OverlayData = medvolLabels.Voxels; vol.OverlayAlphamap = 1;
Display CT Volume as Slice Planes
Visualize the CT volume and label overlay as slice planes. Use the
RenderingStyle name-value argument to specify the rendering style as
"SlicePlanes". Specify the tumor label overlay using the
OverlayData name-value argument.
volSlice = volshow(medVolData.Voxels,OverlayData=medvolLabels.Voxels,Transformation=tform,RenderingStyle="SlicePlanes",Alphamap=linspace(0.01,0.2,256),OverlayAlphamap=0.75);
To scroll through the transverse slices, pause the cursor on the transverse slice until it highlights in blue, then drag the cursor along the z-axis.
Drag the cursor to rotate the volume. The tumor overlay is visible in the slices for which the overlay is defined.
 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.