How to fix this error: Check for incorrect argument data type or missing argument in call to function 'categories'.?

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');
Unrecognized function or variable 'visiondatadir'.
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
/MATLAB/toolbox/matlab/datatypes/categorical/@categorical/categories.m % categorical method /MATLAB/toolbox/matlab/bigdata/@tall/categories.m % tall method /MATLAB/toolbox/parallel/parallel/@codistributed/categories.m % codistributed method
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

@Steven Lord i am biggener in matlab and coding, the class (c) related to pixel labeled crack created by Image labeler App, this app after labeling and when you export labeled image its created folder called PixellabelData but the labeled image in this folder (label_1.png) is black and labeled crack in this image not shown . Thus,I followed the steps in:
The problem is how to read and use this black image to compaire with image(7001-236.png) to get jaccard index because the labeled pixel not shown in the image
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.
@Steven Lord I dont knw what does categorical mean ? the (label_1.png) is the resulted image from image labeler app which is totally black, but i used the following code to show its labeled pixel:
figure;
[i, m] = imread('Label_1.png');
imshow(i,m)
it shows the labeled crack, but I dont know how to use (i,m) in the following code to calculate jaccrad index which is my target :
A = logical(imread('7001-236.png'));
BW_groundTruth =logical(imread(i,m)); % its error
similarity = jaccard(A, BW_groundTruth)
A categorical array contains data representing a finite fixed set of possible values.
sizes = ["small", "medium", "large"]
sizes = 1×3 string array
"small" "medium" "large"
example1 = categorical(sizes, sizes, 'Ordinal', true)
example1 = 1×3 categorical array
small medium large
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char example1 1x3 349 categorical sizes 1x3 258 string
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)
ans = 3×1 cell array
{'small' } {'medium'} {'large' }
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)
Incorrect number or types of inputs or outputs for function categories.
@Steven Lord ok , so what I want exactly from all above is to be able to read the pixel label in the (Label_1.png) which is black image and its pixel labele can be shown only by following:
figure;
[i, m] = imread('Label_1.png');
imshow(i,m)
how can i enter [i,m] which is 0x0 double in the following code to get the jaccard index:
A = logical(imread('7001-236.png'));
BW_groundTruth =logical(imread(i,m)); % its error
similarity = jaccard(A, BW_groundTruth)
?
If (the badly-named) "i" and "m" are length 0, then there is something wrong with your "Label_1.png".
@Image Analyst I used pixel label from image labeler App and after I finished labeling I used Export to file . Then I opened the file which created called PixelLabeData and I found the labeled image is totally black(label_1.png) which is attached and the label pixels not shown, I undertsand that I have to use the following code to let label appear:
figure;
[i, m] = imread('Label_1.png');
imshow(i,m)
but how to use [i,m] or any otherway to let the labeled pixels appear in the image (not to be black image)to be used in jaccard equation to evaluate similarity?

Sign in to comment.

Asked:

on 10 Oct 2023

Commented:

on 10 Oct 2023

Community Treasure Hunt

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

Start Hunting!