Main Content

selectLabelsByGroup

Select ground truth labels by label group

Description

gtLabel = selectLabelsByGroup(gTruth,labelGroups) selects labels belonging to the groups specified by labelGroups 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.

example

Examples

collapse all

Load data to create a ground truth object. Add the image folder to the path.

data = load('stopSignsAndCars.mat');
imageFilenames = data.stopSignsAndCars.imageFilename(1:2)
imageFilenames = 2x1 cell
    {'stopSignImages/image001.jpg'}
    {'stopSignImages/image002.jpg'}

imageFilenames = fullfile(toolboxdir('vision'),'visiondata',imageFilenames);
dataSource = groundTruthDataSource(imageFilenames);

Define labels for identifying ground truth data.

names = {'stopSign';'carRear'};
types = [
    labelType('Rectangle')
    labelType('Rectangle')
    ];
groups = {'TrafficSigns';'Vehicles'};

labelDefs = table(names,types,groups,'VariableNames', {'Name','Type','Group'})
labelDefs=2×3 table
        Name          Type            Group      
    ____________    _________    ________________

    {'stopSign'}    Rectangle    {'TrafficSigns'}
    {'carRear' }    Rectangle    {'Vehicles'    }

Initialize label data for rectangle ROIs.

numRows = numel(imageFilenames);
stopSignTruth = {[856   318    39    41]; [445   523  52    54]};
carRearTruth = {[398   378   315   210]; [332   633   691   287]};

Construct a table containing label data.

labelData = table(stopSignTruth,carRearTruth,'VariableNames',names)
labelData=2×2 table
        stopSign               carRear      
    _________________    ___________________

    {[856 318 39 41]}    {[398 378 315 210]}
    {[445 523 52 54]}    {[332 633 691 287]}

Create a groundTruth object.

gTruth = groundTruth(dataSource,labelDefs,labelData)
gTruth = 
  groundTruth with properties:

          DataSource: [1x1 groundTruthDataSource]
    LabelDefinitions: [2x3 table]
           LabelData: [2x2 table]

Select labels by group.

vehicleGroundTruth = selectLabelsByGroup(gTruth, 'Vehicles')
vehicleGroundTruth = 
  groundTruth with properties:

          DataSource: [1x1 groundTruthDataSource]
    LabelDefinitions: [1x3 table]
           LabelData: [2x1 table]

Input Arguments

collapse all

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

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

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

unique(gTruth.LabelDefinitions.Group)

Example: 'Vehicles'

Example: "Vehicles"

Example: {'Vehicles','Signs'}

Example: ["Vehicles" "Signs"]

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 belonging to the groups specified by the labelGroups input.

Version History

Introduced in R2019a