Finding TP, TN, FP, FN using histc. First Input must be a real non-sparse numeric array (error)

조회 수: 1 (최근 30일)
I am finding TP, TN, FP, FN (confusion matrix) of predicted and actual image. smapImg is the predicted/output image and gtImg is the actual/ground truth image.
TP = histc(smapImg(gtImg), 0:255);
FP = histc(smapImg(~gtImg), 0:255);
FN = histc(~smapImg(gtImg), 0:255);
TN = histc(~smapImg(~gtImg), 0:255);
I am getting this error "First Input must be a real non-sparse numeric array" while computing FN and TN, while TP and FP are computing correctely. Please help.
  댓글 수: 2
Steven Lord
Steven Lord 2019년 8월 20일
What does the following command display? Show all the columns as any of them may contain information important to understanding why you receive that error.
whos smapImg gtImg

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 8월 20일
편집: Adam Danz 2019년 8월 21일
The negation (~) is turnning the array into a logical array. As the error message indicates, the first input is expected to be numeric (not logical).
~smapImg(gtImg)
Example
t = uint8(rand(1,10))
class(t)
ans =
'uint8'
t2 = ~t;
class(t2)
ans =
'logical'
A reproduction of the error using the logical vector
histc(t2,1:3)
Error using histc
First Input must be a real non-sparse numeric array.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by