addLabel
Description
addLabel(
adds the label definition gTruthMed
,labelName
)labelName
to the
LabelDefinitions
property of the specified groundTruthMedical
object gTruthMed
.
addLabel(
optionally specifies the pixel ID or color for the added label using one or more name-value
arguments.gTruthMed
,labelName
,Name=Value
)
Examples
Create Ground Truth Object
Create ground truth data for two chest CT volumes and their corresponding label images, stored in the NIfTI file format. The files are a subset of the Medical Segmentation Decathlon data set [1]. 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");
Create a VolumeSource
object for the two CT volumes.
filePath1 = fullfile(dataFolder,"lung_027.nii.gz"); filePath2 = fullfile(dataFolder,"lung_043.nii.gz"); source = {filePath1; filePath2}; dataSource = medical.labeler.loading.VolumeSource(source);
Specify the names for two label definitions, left_lung
and right_lung
.
labelDefNames = ["left_lung","right_lung"];
Create a groundTruthMedical
object by specifying the CT volume data source and label definition names.
gTruthMed = groundTruthMedical(dataSource,labelDefNames);
The label definitions table contains the specified two labels.
gTruthMed.LabelDefinitions
ans=2×3 table
Name LabelColor PixelLabelID
____________ __________________________ ____________
"left_lung" 0.8667 0.3294 0 1
"right_lung" 0.9294 0.6941 0.1255 2
Add Labels to Ground Truth Object
Add a third label definition, tumor
, to the ground truth object.
addLabel(gTruthMed,"tumor")
Add a fourth label definition, edema
, and specify the color and pixel label ID to associate with the new label.
addLabel(gTruthMed,"edema",LabelColor=[0 1 0],PixelLabelID=10)
The label definitions table now contains four label definitions.
gTruthMed.LabelDefinitions
ans=4×3 table
Name LabelColor PixelLabelID
____________ __________________________ ____________
"left_lung" 0.8667 0.3294 0 1
"right_lung" 0.9294 0.6941 0.1255 2
"tumor" 0.5216 0.0863 0.8196 3
"edema" 0 1 0 10
[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.
Input Arguments
Ground truth data, specified as a groundTruthMedical
object. You can export a
groundTruthMedical
object from the Medical Image Labeler
app or create one programmatically by using the groundTruthMedical
function.
Name of the label to add to the label definitions table, specified as a string
scalar. The name must be different from those of the existing labels in the
LabelDefinitions
property of
gTruth
.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: addLabel(gTruth,"lung",LabelColor=[1 0 0])
assigns the color
red to the new label definition "lung"
.
Pixel label ID for the added label, specified as a positive integer. The pixel
label ID must be different from the IDs of existing labels in the LabelDefinitions
property of
gTruth
.
Example: PixelLabelID=7
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Color for the added label, specified as an RGB triplet. An RGB triplet is a
three-element row vector whose elements specify the intensities of the red, green, and
blue components of the color. The intensities must be in the range [0,
1]
, for example, [0.4 0.6 0.7]
. By default, the
function assigns the next color in the default colormap used by Medical Image
Labeler.
Version History
Introduced in R2025a
See Also
Apps
Objects
Functions
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)