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

1 次查看(过去 30 天)
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

采纳的回答

awezmm
awezmm 2019-7-25
编辑:awezmm 2019-7-25
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 个评论
Tal Nir
Tal Nir 2019-7-29
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!!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by