MATLAB Answers

How to calculate true positive , true negative, false positive and false negative as we have segmented and ground truth

323 views (last 30 days)
calculate true positive , true negative, false positive and false negative as we have segmented and ground truth is that code is correct idx = (expected()==1)
p = length( expected(idx)) n = length( expected(~idx)) N = p+n tp = sum( expected(idx)== predicted(idx)) tn = sum( expected(~idx)== predicted(~idx)) fp = n-tn fn = p-tp
accuracy=(tp+tn)/(tp+tn+fp+fn)

  0 Comments

Sign in to comment.

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 14 Sep 2018
Edited: KALYAN ACHARJYA on 17 Nov 2019
%Last year I answered this way, you can avoid the loop (Recommended)
TP=0;FP=0;TN=0;FN=0;
for i=1:400;
for j=1:400;
if(gold_data(i,j)==1 & test_data(i,j)==1);
TP=TP+1;
elseif(gold_data(i,j)==0 & test_data(i,j)==1);
FP=FP+1;
elseif(gold_data(i,j)==0 & test_data(i,j)==0);
TN=TN+1;
else
FN=FN+1;
end
end
end

  4 Comments

Show 1 older comment
Cretu Ioana
Cretu Ioana on 8 Jun 2019
Coul you tell me who's the gold data and test data? what it means, bacause I also want to calculete FN and TN and I have different notation? thanks
Arslan Ahmed Awan
Arslan Ahmed Awan on 17 Nov 2019
gold_data is your original ground-truth image & test_data will be your segmented-image using your proposed method.
Sameema Tariq
Sameema Tariq on 7 May 2020
Using these tpr and fpr, how will you calculate Reciever Operating Characteristics (ROC)? As ROC is a graph between tpr and fpr on different threshold values, and how will you use it?

Sign in to comment.

More Answers (0)


Translated by