Main Content

groundTruthFromCOCO

Convert COCO JSON file into ground truth object

Since R2025a

Description

gTruth = groundTruthFromCOCO(pathToJSON,pathToImages) converts the COCO-formatted JSON file pathToJSON and the image files in the folder pathToImages into a ground truth object, gTruth.

You can use this function to convert data stored in the COCO JSON format into a ground truth object, and then use the ground truth object to create a datastore for training deep learning models for semantic segmentation, object detection, and instance segmentation tasks.

example

Examples

collapse all

Define the location for annotations and images.

pathToJSON = "cupGtruthCOCO.json";
pathToImages = fullfile(matlabroot,"toolbox","vision","visiondata","imageSets","cups");

Import JSON file to a groundTruth object.

gTruth = groundTruthFromCOCO(pathToJSON,pathToImages);

Open the Image Labeler app with the imported data.

imageLabeler(gTruth)

Input Arguments

collapse all

Path to a JSON file, specified as a character vector or string scalar. The JSON file contains the annotations for the image data.

Folder containing images, specified as a character vector or string scalar.

Output Arguments

collapse all

Ground truth object, returned as a groundTruth.

Version History

Introduced in R2025a