Main Content

selectLabelsByName

Select ground truth labels by label name

Description

example

gtLabel = selectLabelsByName(gTruth,labelNames) selects labels specified by labelNames from a groundTruth object, gTruth. The function returns a corresponding groundTruth object, gtLabel, that contains only the selected labels. If gTruth is a vector of groundTruth objects, then the function returns a vector of corresponding groundTruth objects that contain only the selected labels.

Examples

collapse all

Add the image directory to the MATLAB path.

imageDir = fullfile(matlabroot,'toolbox','vision','visiondata','stopSignImages');
addpath(imageDir);

Load the groundTruth object.

load('stopSignsAndCarsGroundTruth.mat');

View the label definitions.

stopSignsAndCarsGroundTruth.LabelDefinitions
ans=3×3 table
        Name          Type        Group  
    ____________    _________    ________

    {'stopSign'}    Rectangle    {'None'}
    {'carRear' }    Rectangle    {'None'}
    {'carFront'}    Rectangle    {'None'}

Obtain the ground truth data for StopSign label name.

stopSignGroundTruth = selectLabelsByName(stopSignsAndCarsGroundTruth, ...
                                      'stopSign');

Obtain ground truth data for carRear and carFront.

carGroundTruth = selectLabels(stopSignsAndCarsGroundTruth, ...
                                  {'carRear','carFront'});

Remove the image directory from the path.

rmpath(imageDir);

Input Arguments

collapse all

Ground truth, specified as a groundTruth object or vector of groundTruth objects.

Label names, specified as a character vector, string scalar, cell array of character vectors, or string vector.

To view all label names in a groundTruth object, gTruth, enter this command at the MATLAB® command prompt.

gTruth.LabelDefinitions.Name

Example: 'car'

Example: "car"

Example: {'car','lane'}

Example: ["car" "lane"]

Output Arguments

collapse all

Ground truth with only the selected labels, returned as a groundTruth object or vector of groundTruth objects.

Each groundTruth object in gtLabel corresponds to a groundTruth object in the gTruth input. The returned objects contain only the labels with names specified by the labelNames input.

Limitations

  • Selecting pixel labels by name is not supported. However, you can select all labels of type pixel. Use the selectLabelsByType function, specifying the label type as a labelType.PixelLabel enumeration.

  • Selecting sublabels by name is not supported.

Introduced in R2019a