Main Content

groundTruthToOpenLabel

Convert ground truth object to OpenLabel JSON file

Since R2024a

Description

groundTruthToOpenLabel(gTruth,jsonFilename) converts ground truth data gTruth, to the ASAM OpenLABEL® format and writes the result to a JavaScript Object Notation (JSON), jsonFilename.

example

groundTruthToOpenLabel(___,PrettyPrint=false) adds indentations to the output file. A value of true adds the indentation and a value of false will not add it. The default value is set to false, which produces a smaller size file.

Examples

collapse all

Add the folder that contains images to the MATLAB® path.

imageDir = fullfile(matlabroot,"toolbox","vision","visiondata","vehicles");
addpath(imageDir);

Load ground truth object data related to vehicles from a previously saved MAT file.

data = load("vehicleTrainingGroundTruth.mat");
gTruth = data.vehicleTrainingGroundTruth;

Convert the ground truth object data to a JSON file in the ASAM OpenLABEL® format. Set PrettyPrint to true to insert indentations in the output file.

groundTruthToOpenLabel(gTruth,"vehicleGtruthOpenLABEL",PrettyPrint=true);

Inspect the output JSON file by using the edit command:

edit vehicleGtruthOpenLABEL.json

Input Arguments

collapse all

Ground truth object, specified by a groundTruth. Only objects generated by the Image Labeler and those that include image labels can be converted using this function.

JSON filename for the returned file, specified by a character string. For details regarding the JSON format, see ASAM OpenLABEL specification. Not all aspects of the ground truth object data can be represented in the OpenLABEL format. To compensate for the differences and ambiguities between the data that could not be represented and the ASAM specifications, the function makes these customizations to the JSON file:

  • For an image collection used with the Image Labeler, each object in the JSON file's OpenLABEL object_data section, contains a text field that references the location of the images within the file system.

  • Pixel label images are not embedded into the image OpenLABEL object. Instead, they are referenced in the image object using the text field in the object_data_pointer section of the JSON file.

  • Projected cuboids from groundTruth objects are stored as eight points in an OpenLABEL poly2d object modified to accommodate it. These modified poly2d objects are tagged with the boolean field matlab_projected_cuboid set to true.

  • Information stored in the gTruth.LabelDefinitions object such as, Group, Description, and LabelColor is placed in the matlab_label_definitions field of the custom metadata section in the OpenLABEL JSON file

  • Pixel label values to class name correspondences are stored in the custom matlab_label_definitions field of the JSON file.

  • Closed polygons contain a hierarchy field with the top-most layered polygon listed first, with a zero index. In the case of overlapping polygons, the top-layered polygons are marked with lower index numbers than the polygons they cover (below them).

Version History

Introduced in R2024a

See Also

Apps

Objects

Functions