forked from ltnghia/CAMO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRC.m
78 lines (59 loc) · 1.68 KB
/
PRC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [precision, recall] = PRC(smapImg, gtImg)
smapImg = smapImg(:,:,1);
if ~islogical(gtImg)
gtImg = gtImg(:,:,1) > mean2(gtImg(:,:,1));
end
if any(size(smapImg) ~= size(gtImg))
smapImg = imresize(smapImg, [size(gtImg, 1) size(gtImg, 2)]);
end
if (max(smapImg(:)) <= 1)
smapImg = uint8(smapImg * 255);
end
%==========================================================================
precision = [];
recall = [];
%if(unique(smapImg) == 1)
% smapImg(1,1) = 255;
%end
%disp(length(unique(smapImg)));
for i=0:255
threshold = i;
gtImg2 = gtImg;
smapImg2 = smapImg;
%if(length(unique(gtImg2)) == 1)
% gtImg2(1,1) = 1;
% smapImg0 = (smapImg2 >= threshold);
% if(length(unique(smapImg0)) == 1)
% smapImg2(1,1) = 255;
% end
%end
if(sum(smapImg2(:)) == 0)
else
smapImg2(smapImg2<threshold) = 0;
smapImg2(smapImg2>=threshold) = 1;
end
if(sum(gtImg2(:)) == 0)
smapImg2(1,1) = 1;
gtImg2(1,1) = 1;
smapImg2 = 1-smapImg2;
gtImg2 = 1 - gtImg2;
end
gtImg2 = gtImg2 > 0;
smapImg2 = double(smapImg2);
threshold = mean2(smapImg2);
tp = sum(smapImg2(gtImg2) >= threshold);
fp = sum(smapImg2(~gtImg2) >= threshold);
fn = sum(smapImg2(gtImg2) < threshold);
%if(sum(gtImg(:)) == 0 && (sum(sum(smapImg >= threshold)) == 0 || sum(smapImg(:)) == 0))
% precision(i+1) = 1;
% recall(i+1) = 1;
%else
precision(i+1) = tp / (tp + fp + eps);
recall(i+1) = tp / (tp + fn + eps);
%end
%if(sum(gtImg(:)) == 0 && i==0)
% recall(i+1) = 1;
% precision(i+1) = 0;
%end
end
end