How to fix this error: Check for incorrect argument data type or missing argument in call to function 'categories'.?
Show older comments
I applied the fokkowing code to read label pixel image to use it in evaluation jacard index:
dataDir = fullfile(toolboxdir('vision'),'visiondata');
imDir = fullfile(visiondatadir,'crack','7001-236.png');
pxDir = fullfile(visiondatadir,'CrackPixelLabelData_1','Label_1.png');
imds = imageDatastore(imDir);
classNames = ["crack"];
pixelLabelID = [1];
pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);
I = read(imds);
C = read(pxds);
categories(C)
B = labeloverlay(I,C);
figure
imshow(B)
Then, I got the following error:
Check for incorrect argument data type or missing argument in call to function 'categories'.
Error in Untitled5 (line 30)
categories(C)
How to fix it, and how to use the label image in jaccard evaluation code?
Answers (1)
which -all categories
This function is only defined for categorical arrays (and tall categorical and codistributed categorical arrays, I believe.) Is your variable C a categorical array? What does the command class( C) show?
7 Comments
yasmin ismail
on 10 Oct 2023
Edited: yasmin ismail
on 10 Oct 2023
Steven Lord
on 10 Oct 2023
Part of that example to which you linked states: "Read the image and pixel label data. read(pxs) returns a categorical matrix, C. The element C(i,j) in the matrix is the categorical label assigned to the pixel at the location l(i,j)."
Does your pixelLabelDatastore contain categorical data? If not you will not be able to call categories on the data you read from the datastore.
So again, what does this command show?
class(C)
It is possible you can still use your data with the labeloverlay function even if it's not categorical. According to the documentation that function accepts a number of different types of data as its second input: a label matrix, a logical mask, or a categorical array. But if your data isn't categorical you cannot ask for its categories.
yasmin ismail
on 10 Oct 2023
Edited: yasmin ismail
on 10 Oct 2023
sizes = ["small", "medium", "large"]
example1 = categorical(sizes, sizes, 'Ordinal', true)
whos
The variable example1 is a categorical array as you can see from the output of whos. I can ask it what categories it has, what values are allowed to be stored inside it. If I were to try to assign a different value (like "extra large") to it MATLAB would likely error.
categories(example1)
The variable sizes is not a categorical array. MATLAB does not know what to do if I call categories on it so it throws an error.
categories(sizes)
yasmin ismail
on 10 Oct 2023
Image Analyst
on 10 Oct 2023
If (the badly-named) "i" and "m" are length 0, then there is something wrong with your "Label_1.png".
yasmin ismail
on 10 Oct 2023
Categories
Find more on Semantic Segmentation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!