forked from nazikus/dalcim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_coseg.m
98 lines (60 loc) · 2.38 KB
/
run_coseg.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
% Compute solution from Joulin et. al. cvpr'10 and Joulin et al. cvpr'12
addpath(genpath('./'));
computeParameters;% Parameters setting
%%%%%%%%%% Create Mask %%%%%%%%%%%
if param.useMask == 1
param = maskCreator(param);
end
%%%%%%%%%% OPEN FEATURES %%%%%%%%%%%%
[descr, param] = openFeature(param);
%%%%%%%%%% Compute map related to kernel %%%%%%%%%%%%
descr.data = funKernel(descr.data);
[ param.nDescr param.dimDescr] = size(descr.data);
%%%%%%%%%% Compute lambda (regularization parameter) %%%%%%%%%%%%%
[param.lambda, xDif] = computeRegularizationParam(descr.data', param.df);
if param.onlyDiffrac==0 && param.initDiffrac==0
clear xDif
end
%%%%%%%%%% Compute the binary term (Laplacian matrix) %%%%%%%%%%%%%%%
lapMatrix = LaplacianMatrix(descr, param);
%%%%%%%%%% Open superixels %%%%%%%%%
if param.useSuperpix == 1
[projMatrix, supPixIndices, param] = openSuperpixel(descr, param);
lapMatrix = projMatrix' * lapMatrix * projMatrix;
end
lapMatrix = param.lapWght * lapMatrix;
%%%%%%%%%%%%%%%% CVPR'10 %%%%%%%%%%%%%%%%%%%%
if (param.initDiffrac || param.onlyDiffrac)
[labelsDif, labelsDifSoft] = convexQuadraticCoseg(param, projMatrix, lapMatrix, xDif);
if param.ViewOn == 1
plot_groups(param , labelsDif, supPixIndices, 430, 'Joulin et al., CVPR10');
end
if param.onlyDiffrac
return
end
end
%%%%%%%%%%%%%%%% CVPR'12 %%%%%%%%%%%%%%%%%%%%
param = createGroupIndexMatrix(param, descr, projMatrix);
%%%%%%%%%%%%%
if param.initDiffrac
[distParam , y0 ] = initModel(labelsDifSoft, descr.data, param, lapMatrix, projMatrix);
[ y , ~, f ] = EMAlgo(y0 , distParam, descr.data, lapMatrix, param, projMatrix, 1000);
if param.ViewOn == 1
plot_groups(param, y , supPixIndices, 312, 'Joulin et al., CVPR12 - still running');
end
end
for it=1 : param.itMax
[distParamT , y0 ] = initModel(1, descr.data, param, lapMatrix, projMatrix);
[ yT , distParamT, fT ] = EMAlgo( y0 , distParamT , descr.data , lapMatrix , param , projMatrix ,1000);
if (it==1 && ~param.initDiffrac) || fT < f
f = fT;
y = yT;
if param.ViewOn == 1
plot_groups(param, y , supPixIndices, 312, 'Joulin et al., CVPR12 - still running');
end
end
end
if param.ViewOn == 1
plot_groups(param, y , supPixIndices, 312, 'Joulin et al., CVPR12');
end
return