-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparingResults.m
94 lines (77 loc) · 2.28 KB
/
ComparingResults.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [Accuracy,precision,Recall,F1score]=ComparingResults(g1,g2)
% g1=imread('C:\Users\mohammad\Desktop\project\annotations\022_annotation.png');
g1=imresize(g1,[619 697]);
% g2=imread('C:\Users\mohammad\Desktop\untitled.png');
g2=imresize(g2,[619 697]);
[r,c]=size(g1);
%% Labeling The Refrence Image
for i=1:r
for j=1:c/3
if g1(i,j,1)>0 % label red pixels 1
g1(i,j,1)=1;
elseif g1(i,j,2)>0 % label green pixels 2
g1(i,j,2)=2;
end
end
end
%% Labeling The Output Image
for i=1:r
for j=1:c/3
if g2(i,j,1)>0 % label red pixels 1
g2(i,j,1)=1;
elseif g2(i,j,2)>0 % label green pixels 2
g2(i,j,2)=2;
end
end
end
%% False Negetive And True Positives Pixels For Crop Class
FalseNAndTrueP=0;
for i=1:r
for j=1:c/3
if g1(i,j,2)==2 % the green ones in the ref. image
FalseNAndTrueP=FalseNAndTrueP+1;
end
end
end
%% True Negetive And False Positives Pixels For Crop Class
TrueNAndFalseP=0;
for i=1:r
for j=1:c/3
if g1(i,j,1)==1 % the red ones in the ref. image
TrueNAndFalseP=TrueNAndFalseP+1;
end
end
end
%% Calculating True Positive Pixels For Crop Class
TrueP=0;
for i=1:r
for j=1:c/3
if (g1(i,j,2)==2 && g2(i,j,2)==2)% the green ones in the Output image which are green in ref. image too
TrueP=TrueP+1;
end
end
end
%% Calculating False Positive Pixels For Crop Class
FalseP=0;
for i=1:r
for j=1:c/3
if (g1(i,j,1)==1 && g2(i,j,2)==2 ) % the green ones in the Output image which should be red
FalseP=FalseP+1;
end
end
end
%% Calculating precision For crop Class
TruePAndFalseP=TrueP+FalseP;
precision=TrueP/TruePAndFalseP;
if isnan(precision) % check if precision is nan or not
precision=0;
end
%% Calculating Recall For crop Class
Recall=TrueP/FalseNAndTrueP;
%% Calculating F1score For crop Class
FalseN=FalseNAndTrueP-TrueP;
F1score=(2*TrueP)/((2*TrueP)+FalseN+FalseP);
%% Calculating Accuracy For crop Class
TrueN=TrueNAndFalseP-FalseP;
Accuracy=(TrueP+TrueN)/(TrueP+FalseN+FalseP+TrueN);
end