Main Content


Select ground truth labels by label name



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.


collapse all

Add the image directory to the MATLAB path.

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

Load the groundTruth object.


View the label definitions.

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, ...

Obtain ground truth data for carRear and carFront.

carGroundTruth = selectLabels(stopSignsAndCarsGroundTruth, ...

Remove the image directory from the path.


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.


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.


  • 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.

Version History

Introduced in R2019a