-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAppModelEst.m
More file actions
84 lines (72 loc) · 2.66 KB
/
AppModelEst.m
File metadata and controls
84 lines (72 loc) · 2.66 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
function [Qc] = AppModelEst(I, L, Qc_tp, B, Pc)
% [input]
% I : the image obesrvation (the current video frame)
% L : the label map - which pixels would be used
% Qc_tp : the temporally propagated block appearance models
% B : the superpixel blocks
% - S : superpixel labels.
% - G : the pairwise graph structure (a binary matrix)
% - bnum : the number of superpixels
% Pc : the parameters for nonparametric belief propagation
% - minpratio: how many pixels are needed to be an observation of a block
% - kstd : (minimum) bandwidth of the kernels for KDE (observation)
% - nghb : (obs) comparative weight to consider the neighboing blocks
% - foreground : FG model estimation (true) or BG model estimation (false)
% [return]
% Qc : the appearance models of the blocks;
% the marginalized posteriors w.r.t. each RGB random variable
% Authors: Jongwoo Lim (Hanyang U), Bohyung Han (POSTECH)
% APPEARANCE MODEL AGGRAGATION
Qc = cell(1, B.bnum);
Qc_im = cell(1, B.bnum);
hist_cellres = 8;
hist_numcells = ceil(256 / hist_cellres);
% gathering color (appearance) information --------------------------------
% the set of the observed pixel values at each block
[h, w, d] = size(I);
Cdata = reshape(I, [h * w, d])';
Cset = cell(1, B.bnum);
Cwt = cell(1, B.bnum);
block_sizes = zeros(1, B.bnum);
for bidx = 1 : B.bnum
% image (color) observations for each block
pixel_idx = find(B.S == bidx);
l = L(pixel_idx);
Cset{bidx} = Cdata(:, pixel_idx(l > 0.1));
Cwt{bidx} = l(l > 0.1);
block_sizes(bidx) = numel(pixel_idx);
end
for bidx = 1 : B.bnum
hist = HistNew([hist_numcells, hist_numcells, hist_numcells], hist_cellres);
n0 = block_sizes(bidx) - size(Cset{bidx}, 2);
hist = HistAddObs(hist, 'uniform', n0);
if Pc.foreground && size(Cset{bidx}, 2) <= Pc.minpratio * block_sizes(bidx)
continue;
end
Qc{bidx} = HistAddObs(hist, Cset{bidx}, 1);
end
for bidx = 1 : B.bnum
hist = Qc{bidx};
if ~Pc.foreground
% observation on the neighboring block regions
neighbors = find(B.G(:, bidx) > 0);
for i = 1 : numel(neighbors)
nbidx = neighbors(i);
hist = HistAddObs(hist, Qc{nbidx}, Pc.nghb);
end
end
Qc_im{bidx} = HistNormalize(HistConvolve(hist, Pc.kstd));
end
for bidx = 1 : B.bnum
% filtering by the observation model
if ~isempty(Qc_tp{bidx}) && ~isempty(Qc_im{bidx})
Qc{bidx} = HistNormalize(HistProd(Qc_tp{bidx}, Qc_im{bidx}));
elseif isempty(Qc_tp{bidx})
Qc{bidx} = Qc_im{bidx};
elseif isempty(Qc_im{bidx})
Qc{bidx} = Qc_tp{bidx};
else
Qc{bidx} = [];
end
end
end