Why I got error when I used Jaccard similarity coefficient?

조회 수: 5 (최근 30일)
yasmin ismail
yasmin ismail 2023년 10월 3일
답변: Shreeya 2024년 1월 16일
I used the following aklgorithm to evaluate the jaccarrd index:
gT= imread('crack .png');
o=imread('outPut .png');
similarity = jaccard(o, gT)
figure
imshowpair(o, gT)
title(['Jaccard Index = ' num2str(similarity)])
but I got The following error message:
Error using jaccard
Expected input number 1, A, to be one of these types:
logical, double, categorical
Instead its type was uint8.
Error in
jaccard>@(x,name,pos)validateattributes(x,{'logical','double','categorical'},{'real','nonempty','nonsparse'},mfilename,name,pos)
(line 118)
validateInput = @(x,name,pos) validateattributes(x, ...
Error in jaccard (line 123)
validateInput(A,'A',1);
Error in Gtruth1 (line 21)
similarity = jaccard(o, gT)
Thus, how can i fix this error, especially I am new biggener in matlab and I am trying to evaluate the similarity between groundTruth image (crack.png) and the resulted image from my model (outPut.png)?

답변 (1개)

Shreeya
Shreeya 2024년 1월 16일
The jaccard function in MATLAB expectes the input argument images of type logical. The error thrown suggests that the images are of datatype uint8. The documentation linked below can help you understand the usage of the function:
To convert the images to a logical format, you can use the code below:
gT_logical = gT > threshold;
This code is sourced from the following MATALB answer. You can refer to the discussion for more details:

Community Treasure Hunt

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

Start Hunting!

Translated by