This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

groundTruthDataSource

Object for storing ground truth data sources

Description

The groundTruthDataSource object defines the source of ground truth data. Use this object to specify a data source for the groundTruth object. To label the data source, load the groundTruthDataSource object into a labeling app.

  • The Image Labeler supports data sources for collections of images.

  • The Video Labeler and Ground Truth Labeler (requires Automated Driving System Toolbox™) apps support data sources for videos and image sequences. These apps also support custom data sources.

Creation

Syntax

gtSource = groundTruthDataSource(imageFiles)
gtSource = groundTruthDataSource(videoName)
gtSource = groundTruthDataSource(imageSeqFolder)
gtSource = groundTruthDataSource(imageSeqFolder,timeStamps)
gtSource = groundTruthDataSource(sourceName,readerFcn,timeStamps)

Description

example

gtSource = groundTruthDataSource(imageFiles) returns a ground truth data source object for a collection of images specified by imageFiles. Images must be in a file format readable by imread.

gtSource = groundTruthDataSource(videoName) returns a ground truth data source object for a video file specified by videoName. Videos must be in a file format readable by VideoReader.

example

gtSource = groundTruthDataSource(imageSeqFolder) returns a ground truth data source object for an image sequence located in the folder specified by imageSeqFolder.

gtSource = groundTruthDataSource(imageSeqFolder,timeStamps) returns a ground truth data source object for an image sequence with a corresponding timestamp for each image contained in the specified folder. timeStamps sets the TimeStamps property.

example

gtSource = groundTruthDataSource(sourceName,readerFcn,timeStamps) returns a ground truth data source object by using the custom reader function handle, readerFcn. sourceName sets the Source property and timeStamps set the TimeStamps property. The custom reader function loads an image from sourceName that corresponds to the current timestamp specified in the duration vector timeStamps.

Input Arguments

expand all

Image file names, specified as a string array or a cell array of character vectors. Images must be in a file format readable by imread. For a list of the supported image file formats, see imformats.

Name of video file, specified as a string scalar or character vector. Videos must be in a file format readable by VideoReader. For a list of the supported video file formats, see VideoReader.getFileFormats. If your video format is not supported, specify a custom reader function, readerFcn.

Image sequence folder, specified as a string scalar or a character vector. The image files name extensions must be supported by imformats. If your video format is not supported, specify a custom reader function, readerFcn.

The images are loaded in the order returned by the dir command.

Custom reader function, specified as a function handle. The custom reader function must load an image from a source at a specified timestamp by using this syntax:

outputImage = readerFcn(sourceName,currentTimeStamp)
  • readerFcn is the name of your custom reader function.

  • sourceName is the name of the data source.

  • currentTimeStamp is the current timestamp, as specified by the input vector timeStamp.

The outputImage returned by the custom function must be a grayscale or RGB image in any format supported by imshow. For more information, see Use Custom Data Source Reader for Ground Truth Labeling.

Properties

expand all

This property is read-only.

Timestamps of video or image sequence, specified as a duration vector.

  • For a video file, TimeStamps is automatically populated with the timestamps that are present for the video frames.

  • For an image sequence or custom reader, TimeStamps is populated with the values in the input duration vector timeStamps.

  • For an image collection, the TimeStamps property remains empty.

.

This property is read-only.

Source of ground truth data, specified as a character vector or cell array of character vectors. The source name can refer to image file names, a video file name, image sequence file names, or custom data source names.

Examples

collapse all

Use the groundTruthDataSource object to create a data source.

Read a video file and create a data source.

videoName = 'vipunmarkedroad.avi';
dataSource = groundTruthDataSource(videoName)
dataSource = 
groundTruthDataSource for a video file with properties

        Source: ...tlab/toolbox/vision/visiondata/vipunmarkedroad.avi
    TimeStamps: [84x1 duration]

Create a VideoReader to read the video frames.

reader = VideoReader(videoName);

Read the 5th frame in the video and display

 timeStamp = seconds(dataSource.TimeStamps(5));
 reader.CurrentTime = timeStamp;
 I = readFrame(reader);
 
 figure
 imshow(I)

Create a ground truth data source from a an image sequence stored in a specified folder.

Specify the folder containing a sequence of images.

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

Create a data source for the images that are in the imageDir folder.

    dataSource = groundTruthDataSource(imageDir)
dataSource = 
groundTruthDataSource for a video as an image sequence with properties

                      Source: {
                              ' .../Bdoc18b/build/matlab/toolbox/vision/visiondata/building/building1.JPG';
                              ' .../Bdoc18b/build/matlab/toolbox/vision/visiondata/building/building2.JPG';
                              ' .../Bdoc18b/build/matlab/toolbox/vision/visiondata/building/building3.JPG'
                               ... and 2 more
                              }
                  TimeStamps: [5x1 duration]

Read the 5th frame in the sequence.

    I = imread(dataSource.Source{5});
    figure
    imshow(I)

Create a ground truth data source using a custom reader.

Specify image directory containing sequence of road images.

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

Use an image data store as a custom data source.

 imgDataStore = imageDatastore(imageDir);

Write a reader function to read images from the data source. The first input argument, sourceName,of the custom reader function, readerFcn, is not used. The 2nd input, currentTimeStamp,is converted from a duration scalar to a 1-based index suitable for the data source.

readerFcn = @(~,idx)readimage(imgDataStore,seconds(idx));

Create a data source for the images in the imageDir folder using readerFcn.

dataSource = groundTruthDataSource(imageDir,readerFcn,1:5)
dataSource = 
groundTruthDataSource for a custom data source with properties

        Source: ...8b/build/matlab/toolbox/vision/visiondata/building
    TimeStamps: [5x1 duration]

Read the 5th frame in the sequence.

  I = readerFcn(imageDir, seconds(5));
  figure
  imshow(I)

Tips

  • groundTruth objects for video-based groundTruthDataSource objects rely on the video reading capabilities of your operating system. A groundTruth object created using a video data source remains consistent only for the same platform that was used to create it. To create a platform-specific groundTruth object, convert the video into a sequence of images.

Introduced in R2017a