Main Content

removeLabel

Remove label definition from groundTruthMedical object

Since R2025a

    Description

    removeLabel(gTruthMed,labelName) removes the label definition labelName from the LabelDefinitions property of the specified groundTruthMedical object gTruthMed.

    example

    Examples

    collapse all

    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      
    
    

    Remove Label Definition

    Remove the right_lung label from the ground truth object.

    removeLabel(gTruthMed,"right_lung")

    The label definitions table now contains only one label.

    gTruthMed.LabelDefinitions
    ans=1×3 table
           Name                LabelColor            PixelLabelID
        ___________    __________________________    ____________
    
        "left_lung"    0.8667    0.3294         0         1      
    
    

    [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

    collapse all

    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 remove from the label definitions table, specified as a string scalar. The name must match one of the existing labels in the LabelDefinitions property of gTruth.

    Version History

    Introduced in R2025a