selectLabelsByGroup

Select ground truth data for set of labels by group

Description

example

gtLabel = selectLabelsByGroup(gTruth,groups) returns gtLabel, a groundTruth object or an array of groundTruth objects, containing any labels from gTruth that match those specified by groups.

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 array
    {'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   
    ____________    ____________

    {1x4 double}    {1x4 double}
    {1x4 double}    {1x4 double}

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 labels, specified as a groundTruth object or an array of groundTruth objects.

Group names, specified as a cell or string array of character vectors.

Output Arguments

collapse all

Ground truth with only specified labels, returned as a groundTruth object or an array of groundTruth objects, containing any labels from gTruth that match those specified by groups.

Introduced in R2019a