-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCalculate_DiceCoefficient.m
39 lines (37 loc) · 1.3 KB
/
Calculate_DiceCoefficient.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
function DiceCoefficient=Calculate_DiceCoefficient(GroundTruth,Predicted)
%% This code is written for Image Segmentation (EM algorithm)
% This code will return the dice- coefficient for two Images.
% Written By Md. Kamrul Hasan,
%contact: kamruleeekuet@gmail.com
% GroundTruth Means GT Image
% Predicted Means Predicted Image
%%
TruePositive=0;
TrueNegative=0;
FalsePositive=0;
FalseNegative=0;
[row_GT,col_GT]=size(GroundTruth);
[row_Predicted,col_Predicted]=size(Predicted);
if row_GT==row_Predicted && col_GT==col_Predicted
for i=1:1:row_Predicted
for j=1:1:col_GT
if GroundTruth(i,j)==0
if GroundTruth(i,j)==Predicted(i,j)
TrueNegative=TrueNegative+1;
else
FalsePositive=FalsePositive+1;
end
else
if GroundTruth(i,j)==Predicted(i,j)
TruePositive=TruePositive+1;
else
FalseNegative=FalseNegative+1;
end
end
end
end
DiceCoefficient=((2*TruePositive)/(2*TruePositive+FalsePositive+FalseNegative));
else
disp('Sorry!! You are supposed to have same dimentional Image to Calculate DSC.');
end
%% ---------------------------- The End--------------------------------------