I am following the Semantic Segmentation Examples tutorial by MathWorks.

I understand that I can load pixel labeled images

pxDir = fullfile(dataDir,'buildingPixelLabels');

Define the class names.

classNames = ["sky" "grass" "building" "sidewalk"];

Define the label ID for each class name.

pixelLabelID = [1 2 3 4];

and create a pixelLabelDatastore.

pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);

But, how do I create a custom pixel labelled image where every pixel value represents the categorical label of that pixel?

I would then proceed by writing:

pxDir = fullfile(dataDir,'myCustomPixelLabels');

If I understood correctly, imageDatastore holds the actual image and not the pixel labels for that image.


On my system pxDir points to 'C:\Program Files\MATLAB\R2017a\toolbox\vision\visiondata\buildingPixelLabels'. Since I am on Matlab2017a so this example is not included by default, and I cannot compare or view the file to get a better understanding of what I need to do to reproduce this example.


1 Answer 1


The answer can be found here.

Go to the APPS tab, and search for Image Labeler, or Training Image Labeler

Click on Add Images to add your training images.

Click on Add ROI Labels to add class names for the regions of interest.

Proceed to select the regions of interest manually from the uploaded images.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.