forked from YuejiaoGong/PDP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyAlgorithm.m
More file actions
125 lines (100 loc) · 4.92 KB
/
myAlgorithm.m
File metadata and controls
125 lines (100 loc) · 4.92 KB
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
clear, clc,
close all
%% 1. Parameter Settings
dataset = 'ECSSD';
algname = 'myAlg';
SRC = ['Data\',dataset,'\Imgs']; %Path of input images
RES = ['Data\',dataset,'\saliency_',algname]; %Path for saving saliency maps
srcSuffix = '.jpg'; %suffix for your input image
if ~exist(RES, 'dir')
mkdir(RES);
end
addpath(genpath('Funcs'));
%addpath(genpath('Ppcs'));
%% 2. Saliency Map Calculation
files = dir(fullfile(SRC, strcat('*', srcSuffix)));
for k=1:length(files)
srcName = files(k).name;
noSuffixName = srcName(1:end-length(srcSuffix));
disp(k); disp(srcName);
%% Preprocessing: remove image frames
srcImg = imread(fullfile(SRC, srcName));
[noFrameImg, frameRecord] = removeframe(srcImg, 'sobel');
[h, w, chn] = size(noFrameImg);
%% Get depth map
smImg = imresize(noFrameImg, 0.4);
smImg = double(smImg)/255;
trans = CalDepthMap(smImg, 0.95, 5);
depthMap = imresize(trans, [h w]);
minVal = min(depthMap(:));
maxVal = max(depthMap(:));
depthMap = (depthMap - minVal) / (maxVal - minVal + eps);
%% Segment input rgb image into superpixels
pixNumInSP = 600; %pixels in each superpixel
spnumber = round( h * w / pixNumInSP ); %super-pixel number for current image
[idxImg, adjcMatrix, pixelList] = SLIC_Split(noFrameImg, spnumber);
%% Get superpixel properties
spNum = size(adjcMatrix, 1);
[meanPos meanRgbCol meanLabCol meanDepth spSizePb] = ...
GetSuperpixelProperties(pixelList, spNum, h, w, noFrameImg, depthMap);
bdIds = GetBndPatchIds(idxImg);
colDistM = GetDistanceMatrix(meanLabCol);
posDistM = GetDistanceMatrix(meanPos);
texDistM = GetWLDFeatures(pixelList, noFrameImg, spNum);
%% Main procedures
bdCon = BoundaryConnectivity(adjcMatrix, colDistM, bdIds);
[refDepthSharp refDepthSoft] = RefineDepth(meanDepth, bdCon);
bgProb = CalBackgroundProbability(refDepthSharp);
%depDistM = GetDistanceMatrix(refDepth);
bgProbName = ['_bgProbD_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName,bgProbName));
bgSal = 1 - SaveSaliencyMap(bgProb, pixelList, frameRecord, smapName, false, 1);
[CtrC CtrD CtrT CtrF wCtrF]= CalForegroundContrast(colDistM, posDistM, texDistM, bgProb, refDepthSoft, meanPos);
dpName = ['_wCtrF_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
fgSal = SaveSaliencyMap(wCtrF, pixelList, frameRecord, smapName, true);
fusionType = 'optimization';
fusedCtrName = ['_fusedCtr_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, fusedCtrName));
switch fusionType
case 'optimization'
fusedCtr = SaliencyFusionViaOptimization(bgProb, wCtrF, adjcMatrix, bdIds, colDistM, spNum);
%fusedCtr = contrastEnhance(fusedCtr);
% template = calCtrGuassTemp(fusedCtr,meanPos);
% fusedCtr = fusedCtr .* template;
salMap = SaveSaliencyMap(fusedCtr, pixelList, frameRecord, smapName, true);
case 'integration'
salMap = SaliencyFusionViaIntegration(bgSal, fgSal, srcImg);
imwrite(salMap, smapName);
end
FsalMap = PostProcessing2(salMap);
dpName = ['_FINAL_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
imwrite(FsalMap, smapName);
%% Print intermediate results
% depthMap
% dpName = ['_Depth_',algname,'.png'];
% smapName=fullfile(RES, strcat(noSuffixName, dpName));
% SaveSaliencyMap2(depthMap, frameRecord, smapName);
% dpName = ['_DepthRefSoft_',algname,'.png'];
% smapName=fullfile(RES, strcat(noSuffixName, dpName));
% SaveSaliencyMap(refDepthSoft, pixelList, frameRecord, smapName, true);
dpName = ['_CtrC_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
SaveSaliencyMap(CtrC, pixelList, frameRecord, smapName, true);
dpName = ['_CtrD_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
SaveSaliencyMap(CtrD, pixelList, frameRecord, smapName, true);
dpName = ['_CtrT_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
SaveSaliencyMap(CtrT, pixelList, frameRecord, smapName, true);
dpName = ['_CtrF_',algname,'.png'];
smapName=fullfile(RES, strcat(noSuffixName, dpName));
SaveSaliencyMap(CtrF, pixelList, frameRecord, smapName, true);
% CtrName = ['_Ctr_',algname,'.png'];
% smapName=fullfile(RES, strcat(noSuffixName, CtrName));
% SaveSaliencyMap(Ctr, pixelList, frameRecord, smapName, true);
% wCtrName = ['_wCtrF_',algname,'.png'];
% smapName=fullfile(RES, strcat(noSuffixName, wCtrName));
% SaveSaliencyMap(wCtrF, pixelList, frameRecord, smapName, true);
end