extractSlice
Description
Examples
Extract Slice from Medical Image Volume
Extract a slice from a medical image volume created using a chest CT volume saved as a directory of DICOM files. The CT volume is part of a data set containing three CT volumes. The size of the entire data set is approximately 81 MB. Download the data set from the MathWorks® website, then unzip the folder.
zipFile = matlab.internal.examples.downloadSupportFile("medical","MedicalVolumeDICOMData.zip"); filepath = fileparts(zipFile); unzip(zipFile,filepath)
Specify the directory of DICOM files for the first CT volume in the data set.
dataFolder = fullfile(filepath,"MedicalVolumeDICOMData","LungCT01");
Create a medical volume object for the CT volume.
medVol = medicalVolume(dataFolder);
Extract the third slice in the transverse direction.
[X,position,spacings] = extractSlice(medVol,3,"transverse");
The X
output contains the voxel data for the extracted slice.
whos X
Name Size Bytes Class Attributes X 512x512 524288 int16
The position
output provides the patient coordinates of the first voxel in the slice, in millimeters.
position
position = 1×3
-186.5000 -186.5000 -276.2500
The spacings
output provides the in-plane pixel spacing within the extracted slice, in millimeters.
spacings
spacings = 1×2
0.7285 0.7285
Input Arguments
medVol
— Medical volume
medicalVolume
object
Medical volume, specified as a medicalVolume
object.
Note
The extractSlice
function is not valid if the
Orientation
property value of medVol
is
"mixed"
, "oblique"
, or
"unknown"
. In these cases, access the voxel data stored in the
Voxels
property directly using array indexing.
slice
— Slice index
positive integer scalar in range [1, numSlices]
Slice index, specified as a positive integer scalar in the range [1,
numSlices], where numSlices is the number of
slices in the volume along the direction specified by
direction
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
direction
— Direction along which to extract slice
"coronal"
| "sagittal"
| "transverse"
Direction along which to extract the slice information, specified as
"coronal"
, "sagittal"
, or
"transverse"
.
Data Types: char
| string
Output Arguments
X
— Voxel data of extracted slice
m-by-n numeric matrix
position
— Position of upper-left pixel of extracted slice
3-element numeric vector
Position of the upper-left pixel of the extracted slice, returned as a 3-element
numeric vector of the form [x
y
z]. The coordinates are in the patient coordinate system, in the
units specified by the SpatialUnits
property of
medVol
.
spacings
— Spacing between voxel centers in first two dimensions of extracted slice
2-element numeric vector
Spacing between voxel centers in the first two dimensions of the extracted slice,
returned as a 2-element numeric vector of the form
[dim1spacing
dim2spacing]. The values are in the units
specified by the SpatialUnits
property of
medVol
.
Version History
Introduced in R2022b
See Also
medicalVolume
| medicalref3d
| replaceSlice
| sliceCorners
| sliceLimits
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)