-
Notifications
You must be signed in to change notification settings - Fork 0
/
latPosAndScores.m
59 lines (47 loc) · 2.34 KB
/
latPosAndScores.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
function [Positions, MaxScores]=latPosAndScores(model,features,num_parts,level,useDeformationCost)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function computes the latent positions of the
% parts given a feature pyramid and a model with a pretrained
% root filter and part filters. It also computes the scores of the
% parts.
% The output Positions is a nxnum_parts cell array of 2x1 vectors. n is the
% number of model components.
% Positions{i,j}(1,1) and Positions{i,j}(2,1) are the x and y
% coordinate of the latent part position of part j of component i.
% The output MaxScores is a nxnum_parts matrix of scores.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Positions=cell(model.numcomponents,num_parts);
MaxScores=zeros(model.numcomponents,num_parts);
deform=zeros(size(features{level}(:,:,1))); % deform stores deformation cost of a block
a=1:size(deform,2); % a stores indices of columns in the feature window
b=1:size(deform,1); % b stores indices of rows in the feature window
% Iterate through each part to find the latent position
for i=1:model.numcomponents
for j=1:num_parts
partIdx=model.components{i}.parts{j}.partindex;
defIdx=model.components{i}.parts{j}.defindex;
partFilter=model.partfilters{partIdx};
partAnchor=model.defs{defIdx};
% Find cross correlation of the part filter with features
C=imfilter(features{level},partFilter.w);
% Find x and y distlacement matrix;
if useDeformationCost
deform=zeros(size(features{level}(:,:,1)));
d_x=(a-partAnchor(2)); % d_x stores the x deformation from the canonical position
d_y=(b-partAnchor(1)); % d_y stores the y defromation from the canonical position
dx_sq=d_x.^2;
dy_sq=d_y.^2;
for m=1:size(deform,1)
for n=1:size(deform,2)
% Compute the deformation cost as the dot product of the
% deformation feature and the deformations
deform(m,n)=(partAnchor.w).*[d_x(n) d_y(m) dx_sq(n) dy_sq(m)];
end
end
C=C-deform;
end
[dummy_max,dummy_ind]=max(C);
[MaxScores(i,j),Positions{i,j}(1,1)]=max(dummy_max);
Positions{i,j}(2,1)=dummy_ind(dummy_max);
end
end