-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsolveAlphaC2F.m
33 lines (26 loc) · 1.06 KB
/
solveAlphaC2F.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
function alpha=solveAlphaC2F(I,consts_map,consts_vals,levels_num,active_levels_num,varargin)
if (length(varargin)>0)
if (~isempty(varargin{1}))
thr_alpha=varargin{1};
end
end
if (~exist('thr_alpha','var'))
thr_alpha=0.02;
end
erode_mask_w=1;
active_levels_num=max(active_levels_num,1);
if (levels_num>1)
sI=downSmpIm(I,2);
s_consts_map=round(downSmpIm(double(consts_map),2));
s_consts_vals=round(downSmpIm(double(consts_vals),2));
s_alpha=solveAlphaC2F(sI,s_consts_map,s_consts_vals,levels_num-1,...
min(levels_num-1,active_levels_num),varargin{:});
alpha=upSampleAlphaUsingImg(s_alpha,sI,I,varargin{2:end});
talpha=alpha.*(1-consts_map)+consts_vals;
consts_map=min(consts_map+imerode((alpha>=(1-thr_alpha)),ones(erode_mask_w*2+1))+imerode((alpha<=(thr_alpha)),ones(erode_mask_w*2+1)),1);
consts_vals=round(talpha).*consts_map;
%figure, imshow([consts_map,alpha])
end
if (active_levels_num>=levels_num)
alpha=solveAlpha(I,consts_map,consts_vals,varargin{2:end});
end