image labelling for background

29 views (last 30 days)
fatihveysel nurcin
fatihveysel nurcin on 8 Apr 2019
Answered: OJ27 on 22 Apr 2020
I want to label images in order to use it in semantic segmentation
However, i want to label only specific area,
so if i only mark specific areas in whole image dataset
the areas which are not mark are automatically assumed as background?
Or do i have to mark it manually mark it as background as well?

Answers (2)

Image Analyst
Image Analyst on 8 Apr 2019
It depends on what you want to do. If you only process the things you have labeled, then you don't need to worry about the background being labeled since even if it were, you'd not process it. If you want to process it, then you need to label it.
OJ27 on 22 Apr 2020
any solution to this? is there an automatic way to label the undefined pixels as background? I want to use a cnn to do semantic segmentation of a specific object. The examples MATLAB offers come with datasets that two classes and no undefined pixels.

Sign in to comment.

OJ27 on 22 Apr 2020
So I solved this by only labeling the desired areas in my images with the class cat and the background was left without a label.
pxDir = fullfile('...'); % insert your directory
imds = imageDatastore('...'); % insert your directory
classNames = ["cat"];
pixelLabelID = [1];
pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);
C = readimage(pxds,1);
undefinedPixels = isundefined(C);
If you look at C, the entries are either '<undefined>' or 'cat'. Also if you look at undefinedPixels you'll see how many of the pixels have this label and you can even plot it. So I replaced these two lines
classNames = ["cat","background"];
pixelLabelID = [1,0];
and now C shows either 'background' or 'cat'. If you run the
undefinedPixels = isundefined(C);
again, you'll find sum(sum(undefinedPixels)) is zero.




Community Treasure Hunt

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

Start Hunting!