Use Custom Image Source Reader for Labeling

The Video Labeler and Ground Truth Labeler (requires Automated Driving Toolbox™) apps enable you to label ground truth data in a video or sequence of images.

You can use a custom reader to import any video or sequence of images that is supported by the VideoReader object or imread function. First, create a custom reader function. Then, load the custom reader function and corresponding image data source into the Video Labeler or Ground Truth Labeler app. The Image Labeler app does not support custom data source readers.

Create Custom Reader Function

First, specify a custom reader as a function handle. The custom reader must have this syntax.

outputImage = readerFcn(sourceName,currentTimestamp)
In this example, readerFcn is the name of the custom reader function.

The custom reader function loads an image from sourceName, which corresponds to the current timestamp specified by currentTimestamp. For example, suppose you want to load the image at the third timestamp for a timestamps duration vector that runs from 1 to 5 seconds. To specify currentTimestamp, at the MATLAB® command prompt, enter this code.

timestamps = seconds(1:5);
currIdx = 3;
currentTimestamp = timestamps(currIdx);

The outputImage output from the custom function must be a grayscale or RGB image in any format supported by the imshow function. The currentTimestamp output is a scalar value that corresponds to the current frame that the function is executing.

Import Data Source into Video Labeler App

To import a custom data source into the Video Labeler app, first create a groundTruthDataSource object. This object stores the data source files and timestamps. Specify the name of the data source, the custom reader function handle that reads the data, and the timestamps by using this syntax.

gtSource = groundTruthDataSource(sourceName,readerFcn,timestamps)

To load this object into the app, at the MATLAB command prompt, enter this code.


Alternatively, on the toolstrip of the Video Labeler app, select Load > Custom Reader. Then, in the Load Custom Data Source dialog box, specify Custom reader function as a function handle and also specify Data source name. In addition, you must import corresponding timestamps from the MATLAB workspace.

Import Data Source into Ground Truth Labeler App

To import the custom image data source into the Ground Truth Labeler app, on the app toolstrip, select Open > Add Signals. Then, in the dialog box, set Source Type to Custom Image. You can then specify the custom reader function, data source name, and timestamps, and then click Add Source to load the image data source.

See Also



Related Topics