Main Content


Select ground truth labels by label type



gtLabel = selectLabelsByType(gTruth,labelTypes) selects labels of the types specified by labelTypes 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 Rectangle labelType.

rectGroundTruth = selectLabelsByType(stopSignsAndCarsGroundTruth,labelType.Rectangle);

Remove the image directory from the path.


Input Arguments

collapse all

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

Label types, specified as a labelType enumeration or vector of labelType enumerations.

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


Example: labelType.Rectangle

Example: [labelType.Rectangle labelType.Line]

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 that are of the types specified by the labelTypes input.


  • Selecting sublabels by type is not supported.

Version History

Introduced in R2019a