createMask
Create volumetric mask from dicomContours object
Description
creates the volumetric mask BW = createMask(rtContours,roiIndex,spatial)BW, a voxel representation of the specified
ROI roiIndex from the dicomContours object
rtContours. The roiIndex argument specifies
which contour in rtContours to create a mask from.
spatial specifies the location, resolution, and orientation of the
3-D data in world coordinates.
Examples
Read the metadata of a DICOM-RT structure set file [1].
info = dicominfo("RTSTRUCT-VS-SEG-001.dcm");Construct a dicomContours object from the metadata.
rtContours = dicomContours(info);
Display all of the ROI information as a table.
rtContours.ROIs
ans=4×5 table
Number Name ContourData GeometricType Color
______ ___________ ___________ _____________ ____________
1 {'TV' } {13×1 cell} {13×1 cell} {3×1 double}
2 {'Cochlea'} { 5×1 cell} { 5×1 cell} {3×1 double}
3 {'Vol2016'} {12×1 cell} {12×1 cell} {3×1 double}
4 {'*Skull' } {79×1 cell} {79×1 cell} {3×1 double}
The createMask function requires an imref3d object that defines the spatial referencing for the new mask.
A common approach is to match the spatial referencing of the scan on which the contour was drawn so you can overlay the mask on the scan volume. This requires the patient position, voxel spacing, and volume size in pixels, which you can get from the scan metadata by using the dicominfo function.
This example specifies values based on the published data set, with spacing in millimeters [1].
imagePositionPatient = [-105.00000002155, -125.02819822065, -77.834300994873]; pixelSpacing = 0.546875; sliceSpacing = 1.5; numRows = 384; numCols = 384; numSlices = 80;
Calculate the edge-to-edge limits for the mask, in millimeters. The imagePositionPatient metadata specifies the center of the first voxel, so you calculate the minimum edge by subtracting half the pixel size from the patient position value.
xWorldMin = imagePositionPatient(1) - pixelSpacing/2; xWorldMax = xWorldMin + (numCols * pixelSpacing); xWorldLimits = [xWorldMin xWorldMax]; yWorldMin = imagePositionPatient(2) - pixelSpacing/2; yWorldMax = yWorldMin + (numRows * pixelSpacing); yWorldLimits = [yWorldMin yWorldMax]; zWorldMin = imagePositionPatient(3) - sliceSpacing/2; zWorldMax = zWorldMin + (numSlices * sliceSpacing); zWorldLimits = [zWorldMin zWorldMax];
Construct the imref3d object.
R = imref3d([numRows, numCols, numSlices], xWorldLimits, yWorldLimits, zWorldLimits);
Create a 3-D logical mask of the first contour. Specify the third argument as the imref3d object R.
contourIndex = 1; rtMask = createMask(rtContours,contourIndex,R);
Display the mask as a volumetric image. The mask shows the contoured region of interest TV as a 3-D volume. To overlay a mask on the scan, you can call volshow and specify the input data as the scan volume and the OverlayData name-value argument as the mask.
volshow(rtMask,Transformation=R);

References
[1] Shapey, J., Kujawa, A., Dorent, R., Wang, G., Bisdas, S., Dimitriadis, A., Grishchuck, D., Paddick, I., Kitchen, N., Bradford, R., Saeed, S., Ourselin, S., & Vercauteren, T. (2021). Segmentation of Vestibular Schwannoma from Magnetic Resonance Imaging: An Open Annotated Dataset and Baseline Algorithm (version 2) [Data set]. The Cancer Imaging Archive. https://doi.org/10.7937/TCIA.9YTJ-5Q73. Licensed under the CC-BY-4.0 License available at https://creativecommons.org/licenses/by/4.0/.
Input Arguments
DICOM contours, specified as a dicomContours object.
Data Types: dicomContours
ROI in a DICOM contours object, specified as a positive integer, character vector,
or string scalar. The value depends on which ROI identifier in the ROIs table of the
dicomContours object you use.
| ROI Identifier | Type | Example |
|---|---|---|
Number | Row of the ROI in the ROIs table of the rtContours
object, specified as a positive integer. Number is the first
column in the ROIs table. | rtMask = createMask(rtContours,1,spatialInfo) |
Name
| Name of the ROI in the ROIs table of the rtContours
object, specified as a character vector or string scalar.
Name is the second column in the ROIs table. | rtMask =
createMask(rtContours,"Body_Contour",spatialInfo) |
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string
Spatial referencing information, specified as a structure or an imref3d object. You can use a structure returned by dicomreadVolume that contains the fields
PatientPosition, PixelSpacing, and
PatientOrientation. Spatial referencing information provides the
location, resolution, and orientation of the 3-D coordinate data.
Output Arguments
Volumetric mask, returned as a 3-D logical array. The mask uses the intrinsic image
coordinate system defined by spatial.
Extended Capabilities
The createMask function fully supports
thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2020bcreateMask now supports thread-based
environments.
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)