-
Notifications
You must be signed in to change notification settings - Fork 16
/
demo.m
66 lines (51 loc) · 1.92 KB
/
demo.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
close all; clear; clc;
% set the RoodDir according to your own environment
RootDir = pwd;
% set the ground truth path and the foreground map path
gtPath = fullfile(RootDir,'demo','GT');
fgPath = fullfile(RootDir,'demo','FG');
% set the result path
resPath = fullfile(RootDir,'demo','Result');
if ~exist(resPath,'dir')
mkdir(resPath);
end
% set the foreground map methods
MethodNames = {'MDF','mc','DISC','rfcn','DCL','dhsnet'};
% load the gtFiles
gtFiles = dir(fullfile(gtPath,'*.png'));
% for each gtFiles
for i = 1:length(gtFiles)
fprintf('Processing %d/%d...\n',i,length(gtFiles));
% load the gt file
[GT,map] = imread(fullfile(gtPath,gtFiles(i).name));
if numel(size(GT))>2
GT = rgb2gray(GT);
end
GT = logical(GT);
% in some dataset(ECSSD) some ground truth is reverse when map is not none
if ~isempty(map) && (map(1)>map(2))
GT = ~GT;
end
% for each saliency method
for j = 1 : length(MethodNames)
% load the saliency map file
predname = [gtFiles(i).name(1:end-4) '_' MethodNames{j} '.png'];
prediction = imread(fullfile(fgPath,predname));
if numel(size(prediction))>2
prediction = rgb2gray(prediction);
end
% Normalize the prediction.
d_prediction = double(prediction);
if (max(max(d_prediction))==255)
d_prediction = d_prediction./255;
end
d_prediction = reshape(mapminmax(d_prediction(:)',0,1),size(d_prediction));
% evaluate the predicted map against the GT
score = StructureMeasure(d_prediction,GT);
score = roundn(score,-4);
% save the result
resName = sprintf([gtFiles(i).name(1:end-4) '_%.4f_' MethodNames{j} '.png'],score);
imwrite(prediction,fullfile(resPath,resName));
end
end
fprintf('The results are saved in %s\n',resPath);