Main Content

vision.labeler.loading.CustomImageSource Class

Namespace: vision.labeler.loading
Superclasses: vision.labeler.loading.MultiSignalSource

Load signals from custom image sources into Ground Truth Labeler app

Since R2020a

Description

The vision.labeler.loading.CustomImageSource class creates an interface for loading signals from custom image data sources into the Ground Truth Labeler app. In the Add/Remove Signal dialog box of the app, when Source Type is set to Custom Image, this class controls the parameters in that dialog box.

Add/Remove Signal dialog box with Source Type set to Custom Image

To access this dialog box, in the app, select Import > Add Signals.

The vision.labeler.loading.CustomImageSource class is a handle class.

Creation

When you export labels from a Ground Truth Labeler app session that contains custom image sources, the exported groundTruthMultisignal object stores instances of this class in its DataSource property.

To create a CustomImageSource object programmatically, such as when programmatically creating a groundTruthMultisignal object, use the vision.labeler.loading.CustomImageSource function (described here).

Description

customImgSource = vision.labeler.loading.CustomImageSource creates a CustomImageSource object for loading signals from custom image data sources. To specify the data source and the parameters required to load the source, use the loadSource method.

example

Properties

expand all

Name of the type of source that this class loads, specified as a string scalar.

Attributes:

GetAccess
public
Constant
true
NonCopyable
true

Description of the functionality that this class provides, specified as a string scalar.

Attributes:

GetAccess
public
Constant
true
NonCopyable
true

Name of the data source, specified as a string scalar. Typically, SourceName is the name of the file from which the signal is loaded.

Attributes:

GetAccess
public
SetAccess
protected

Parameters for loading a custom image signal from a data source, specified as a structure.

This table describes the required and optional fields of the SourceParams structure.

FieldDescriptionRequired or Optional
FunctionHandleCustom reader function for reading images from the data source, specified as a function handle. In the Add/Remove Signal dialog box of the app, specify this function handle in the Custom Reader Function parameter. For details on creating a custom reader function, see Use Custom Image Source Reader for Labeling.

Required

Timestamps

Timestamps for the custom image signal, specified as a cell array containing a single duration vector of timestamps. (For data sources that contain multiple signals, the Timestamps cell array contains one duration vector per signal with timestamps that are loaded from the MATLAB® workspace.)

In the Add/Remove Signal dialog box of the app, when you click the Import from Workspace button to read the timestamps from a variable in the MATLAB workspace, then the SourceParams property stores these timestamps in the Timestamps field.

Required

Attributes:

GetAccess
public
SetAccess
protected

Names of the signals that can be loaded from the data source, specified as a string vector.

Attributes:

GetAccess
public
SetAccess
protected

Types of the signals that can be loaded from the data source, specified as a vector of vision.labeler.loading.SignalType enumerations. Each signal listed in the SignalName property is of the type in the corresponding position of SignalType.

Attributes:

GetAccess
public
SetAccess
protected

Timestamps of the signals that can be loaded from the data source, specified as a cell array of duration vectors. Each signal listed in the SignalName property has the timestamps in the corresponding position of Timestamp.

Attributes:

GetAccess
public
SetAccess
protected

Number of signals that can be read from the data source, specified as a nonnegative integer. NumSignals is equal to the number of signals in the SignalName property.

Attributes:

GetAccess
public
SetAccess
public
Dependent
true
NonCopyable
true

Methods

expand all

Examples

collapse all

Specify the path to a folder containing a sequence of road images.

imageFolder = fullfile(toolboxdir('driving'),'drivingdata','roadSequence');

Store the images in an image datastore. The Ground Truth Labeler app and groundTruthMultisignal object do not natively support image datastores, so it is considered a custom image data source.

imds = imageDatastore(imageFolder);

Write a reader function, readerFcn, to read images from the datastore. The first input argument to the reader function, sourceName, is not used. The second input argument, currentTimestamp, is converted from a duration scalar to a 1-based index. This format is compatible with reading images from the datastore.

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

Create a custom image source. Load the source name, reader function, and first five timestamps of the datastore into the CustomImageSource object.

sourceName = imageFolder;
sourceParams = struct();
sourceParams.FunctionHandle = readerFcn;
sourceParams.Timestamps = seconds(1:5);
customImgSource = vision.labeler.loading.CustomImageSource;
loadSource(customImgSource,sourceName,sourceParams)

Read the first frame in the sequence. Display the frame.

signalName = customImgSource.SignalName;
I = readFrame(customImgSource,signalName,1);
figure
imshow(I)

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

Tips

  • You can this class as a starting point for creating a custom data source loading class. To view the source code for this class, use this command:

    edit vision.labeler.loading.CustomImageSource

Version History

Introduced in R2020a