-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
135 lines (90 loc) · 4.36 KB
/
main.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
clear all;
close all;
clc;
SalMapPath = '../CamMap/';
Models = {'2020-CVPR-SINet'};
modelNum = length(Models);
DataPath = '../CamDataset/';
Datasets = {'COD10K'};
ResDir = '../Results/Result-COD10K-test/';
ResName='_result.txt';
Thresholds = 1:-1/255:0;
datasetNum = length(Datasets);
for d = 1:datasetNum
tic;
dataset = Datasets{d}
fprintf('Processing %d/%d: %s Dataset\n',d,datasetNum,dataset);
ResPath = [ResDir dataset '-mat/'];
if ~exist(ResPath,'dir')
mkdir(ResPath);
end
resTxt = [ResDir dataset ResName];
fileID = fopen(resTxt,'w');
for m = 1:modelNum
model = Models{m}
gtPath = [DataPath dataset '/'];
salPath = [SalMapPath model '/' dataset '/'];
imgFiles = dir([salPath '*.png']);
imgNUM = length(imgFiles);
[threshold_Fmeasure, threshold_Emeasure] = deal(zeros(imgNUM,length(Thresholds)));
[threshold_Precion, threshold_Recall] = deal(zeros(imgNUM,length(Thresholds)));
[Smeasure, wFmeasure, adpFmeasure, adpEmeasure, MAE] =deal(zeros(1,imgNUM));
for i = 1:imgNUM
fprintf('Evaluating(%s Dataset,%s Model): %d/%d\n',dataset, model, i,imgNUM);
name = imgFiles(i).name;
gt = imread([gtPath name]);
if (ndims(gt)>2)
gt = rgb2gray(gt);
end
if ~islogical(gt)
gt = gt(:,:,1) > 128;
end
sal = imread([salPath name]);
if size(sal, 1) ~= size(gt, 1) || size(sal, 2) ~= size(gt, 2)
sal = imresize(sal,size(gt));
imwrite(sal,[salPath name]);
fprintf('Error occurs in the path: %s!!!\n', [salPath name]);
end
sal = im2double(sal(:,:,1));
sal = reshape(mapminmax(sal(:)',0,1),size(sal));
Smeasure(i) = StructureMeasure(sal,logical(gt));
wFmeasure(i) = original_WFb(sal,logical(gt));
threshold = 2* mean(sal(:)) ;
[~,~,adpFmeasure(i)] = Fmeasure_calu(sal,double(gt),size(gt),threshold);
Bi_sal = zeros(size(sal));
Bi_sal(sal>threshold)=1;
adpEmeasure(i) = Enhancedmeasure(Bi_sal,gt);
[threshold_F, threshold_E] = deal(zeros(1,length(Thresholds)));
[threshold_Pr, threshold_Rec] = deal(zeros(1,length(Thresholds)));
for t = 1:length(Thresholds)
threshold = Thresholds(t);
[threshold_Pr(t), threshold_Rec(t), threshold_F(t)] = Fmeasure_calu(sal,double(gt),size(gt),threshold);
Bi_sal = zeros(size(sal));
Bi_sal(sal>threshold)=1;
threshold_E(t) = Enhancedmeasure(Bi_sal,gt);
end
threshold_Fmeasure(i,:) = threshold_F;
threshold_Emeasure(i,:) = threshold_E;
threshold_Precion(i,:) = threshold_Pr;
threshold_Recall(i,:) = threshold_Rec;
MAE(i) = mean2(abs(double(logical(gt)) - sal));
end
column_F = mean(threshold_Fmeasure,1);
meanFm = mean(column_F);
maxFm = max(column_F);
column_Pr = mean(threshold_Precion,1);
column_Rec = mean(threshold_Recall,1);
column_E = mean(threshold_Emeasure,1);
meanEm = mean(column_E);
maxEm = max(column_E);
Sm = mean2(Smeasure);
wFm = mean2(wFmeasure);
adpFm = mean2(adpFmeasure);
adpEm = mean2(adpEmeasure);
mae = mean2(MAE);
save([ResPath model],'Sm','wFm', 'mae', 'column_Pr', 'column_Rec', 'column_F', 'adpFm', 'meanFm', 'maxFm', 'column_E', 'adpEm', 'meanEm', 'maxEm');
fprintf(fileID, '(Dataset:%s; Model:%s) Smeasure:%.3f; wFmeasure:%.3f;MAE:%.3f; adpEm:%.3f; meanEm:%.3f; maxEm:%.3f; adpFm:%.3f; meanFm:%.3f; maxFm:%.3f.\n',dataset,model,Sm, wFm, mae, adpEm, meanEm, maxEm, adpFm, meanFm, maxFm);
fprintf('(Dataset:%s; Model:%s) Smeasure:%.3f; wFmeasure:%.3f;MAE:%.3f; adpEm:%.3f; meanEm:%.3f; maxEm:%.3f; adpFm:%.3f; meanFm:%.3f; maxFm:%.3f.\n',dataset,model,Sm, wFm, mae, adpEm, meanEm, maxEm, adpFm, meanFm, maxFm);
end
toc;
end