MATLAB: Using ‘pixelLabelDatastore’ to label pixels returns the pixels as

Computer Vision Toolbox

I am using the command
pxds = pixelLabelDatastore(labelDir,classes,labelIDs);
to label the pictures in the directory 'labelDir' to the categories in 'classes' using the RBG pixel IDs set in 'labelIDs'. However, when I use the command
X = readimage (pxds, 1);
to check if the labelling has been done correct, all my pixels appear as <undefined>. Why is this happening?

Best Answer

The "label" images in 'labelDir' have more than two unique RGB triplet values. If the right RGB triplets are not selected in 'labelIDs', most of the pixels will be marked as undefined because their RGB triplet values do not correspond to the value specified in pixelLabelDatastore.
You can use IMTOOL to see all the different RGB pixel values in the label image.