How to write the labeled images for training a sematic clssifier without using image labeler?

1 view (last 30 days)
Hi,
I want to train a semantic classifier through images made from a simulation process, I have the ground truth classification, and therefore I don't need the image labeler app.
However, I found explanation only on how to write ground truth by the image labeler app, or by commands which add labels inside a rectangle, etc...
However, I have the ground truth image with all the labels, I just want to save it in a proper manner and traing a sematic classifier from matlab, how do I do that?
I also looked in an example ground truth data, it looks like a color image, how do I write this color image from the labels?
Please help!
Thanks,
Dr. Tal Nir

Accepted Answer

awezmm
awezmm on 25 Jul 2019
Edited: awezmm on 25 Jul 2019
After labeling, you should have two sets of images. The first set will be the original images and the second set will be the categorial images with labels.
For semantic segmentation you should create datastores:
imds = imageDatastore(imgDir); %corresponding to the original images
pxds = pixelLabelDatastore(labelDir,classes,labelIDs); %corresponding to labeled images
The example link above explains this in more detail.
Note that imgDir and labelDir can simply be a cell array of the filepaths to the images, in corresponding order
For instance:
imgDir = {"~/Users/awz/img1.tif", "~/Users/awz/img2.tif", "~/Users/awz/img3.tif"};
labelDir = {"~/Users/awz/label1.tif", "~/Users/awz/label2.tif", "~/Users/awz/label3.tif"};
classes = ["class1", "class2", "class3"];
labelIDs = [1 2 3];
imds = imageDatastore(imgDir);
pxds = pixelLabelDatastore(labelDir,classes,labelIDs);
  1 Comment
Tal Nir
Tal Nir on 29 Jul 2019
It took me some time to build and test the code incorporating your answer, but at the end its worth the effort, it works very well.
Thank you very much for your help!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!