Main Content

groundTruthDataSource

Object for storing ground truth data sources

Description

ThegroundTruthDataSourceobject defines the source of ground truth data. Use this object to specify a data source for thegroundTruthobject. To label the data source, load thegroundTruthDataSourceobject into a labeling app.

  • TheImage Labelersupports data sources for collections of images.

  • TheVideo Labelersupports data sources for videos and image sequences. This app also supports custom data sources.

Creation

Description

Image Datastore Source

gtSource= groundTruthDataSource(imds)returns a ground truth data source object for animageDatastorespecified byimds.

Collection of Images Source

example

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

Video File Source

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

Video as a Sequence of Images Source

example

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

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.timestampssets theTimeStampsproperty.

Custom Data Source

example

gtSource= groundTruthDataSource(sourceName,readerFcn,timestamps)returns a ground truth data source object by using the custom reader function handle,readerFcn.sourceNamesets theSourceproperty andtimestampsset theTimeStampsproperty. The custom reader function loads an image fromsourceNamethat corresponds to the current timestamp specified in thedurationvectortimestamps.

Input Arguments

expand all

Image datastore, specified as animageDatastoreobject.

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

Name of video file, specified as a string scalar or character vector. Videos must be in a file format readable byVideoReader. For a list of the supported video file formats, seeVideoReader.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 byimformats. If your video format is not supported, specify a custom reader function,readerFcn.

The images are loaded in the order returned by thedircommand.

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)
  • readerFcnis the name of your custom reader function.

  • sourceNameis the name of the data source.

  • currentTimestampis the current timestamp, as specified by the input vectortimestamp.

TheoutputImagereturned by the custom function must be a grayscale or RGB image in any format supported byimshow. For more information, seeUse Custom Image Source Reader for Labeling.

Properties

expand all

This property is read-only.

Timestamps of video or image sequence, specified as adurationvector.

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

  • For an image sequence or custom reader,Timestampsis populated with the values in the inputdurationvectortimestamps.

  • For an image collection, theTimeStampsproperty 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

Load image collection file names.

imageDir = fullfile(matlabroot,'toolbox','vision','visiondata','bookCovers'); imds = imageDatastore(imageDir);

Create a data source from an image datastore.

dataSource = groundTruthDataSource(imds);

Read and display an image from the datastore.

I = read(dataSource.Source); figure,imshow(I)

Figure contains an axes object. The axes object contains an object of type image.

Use thegroundTruthDataSourceobject 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)

Figure contains an axes object. The axes object contains an object of type image.

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

dataSource = groundTruthDataSource(imageDir)
dataSource = groundTruthDataSource for a video as an image sequence with properties Source: { ' .../Bdoc22a/build/matlab/toolbox/vision/visiondata/building/building1.JPG'; ' .../Bdoc22a/build/matlab/toolbox/vision/visiondata/building/building2.JPG'; ' .../Bdoc22a/build/matlab/toolbox/vision/visiondata/building/building3.JPG' ... and 2 more } TimeStamps: [5x1 duration]

Read the 5th frame in the sequence.

我= imread (dataSource.Source {5});图imshow(我)

Figure contains an axes object. The axes object contains an object of type image.

Create a ground truth data source by using a custom reader function.

Specify an image folder containing a sequence of road images.

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

Use an image datastore as the custom data source.

imgDataStore = imageDatastore(imgFolder);

Write a reader function,readerFcn, to read images from the datastore. The first input argument,sourceName, is not used. The second input argument,currentTimestamp, is the current timestamp. The function convertscurrentTimestampfrom adurationscalar to a 1-based index suitable for reading images from the datastore.

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

Create a data source for the images in the image folder by using the custom reader function.

dataSource = groundTruthDataSource(imgFolder,readerFcn,1:5)
dataSource = groundTruthDataSource for a custom data source with properties Source: ...2a/build/matlab/toolbox/vision/visiondata/building TimeStamps: [5x1 duration]

Read the fifth frame in the sequence.

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

Figure contains an axes object. The axes object contains an object of type image.

Tips

  • groundTruthobjects for video-basedgroundTruthDataSourceobjects rely on the video reading capabilities of your operating system. AgroundTruthobject created using a video data source remains consistent only for the same platform that was used to create it. To create a platform-specificgroundTruthobject, convert the video into a sequence of images.

Version History

Introduced in R2017a