-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathtestingsetGeneration.m
59 lines (52 loc) · 2.45 KB
/
testingsetGeneration.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
% Codes for CVPR-15 work `Face Alignment by Coarse-to-Fine Shape Searching'
% Any question please contact Shizhan Zhu: zhshzhutah2@gmail.com
% Released on July 25, 2015
function [images,T] = testingsetGeneration(img_root,nameList,bbox,...
priorModel,priorsInfo,mean_simple_face,target_simple_face)
assert(~xor(nargout >= 3,exist('data','var')));
m = length(nameList);
assert(size(bbox,1)==m);
p = zeros(m,8);
p(:,1:4) = repmat(bbox(:,1),1,4) + ...
repmat(mean_simple_face(:,1:4),m,1) .* repmat(bbox(:,2)-bbox(:,1),1,4);
p(:,5:8) = repmat(bbox(:,3),1,4) + ...
repmat(mean_simple_face(:,5:8),m,1) .* repmat(bbox(:,4)-bbox(:,3),1,4);
Tb = getTransToSpecific(p,target_simple_face * priorsInfo.win_size);
ori_images = cell(m,1);
images = cell(m,1);
for i = 1:m
img = imread([img_root nameList{i}]);
img = im2uint8(img);
if size(img,3)>1, img = rgb2gray(img);end;
ori_images{i} = img;
images{i} = imtransform(img,Tb(i),'XData',[1 priorsInfo.win_size],...
'YData',[1,priorsInfo.win_size]);
end;
rotationCenter = priorsInfo.win_size * priorsInfo.rotationCenter;
extractWindow = priorsInfo.win_size * priorsInfo.extractWindow;
assert(extractWindow(4)-extractWindow(3) == extractWindow(2)-extractWindow(1));
extractCellSize = (extractWindow(4)-extractWindow(3)) / priorsInfo.extractCellNum;
predicted = zeros(m,2);
F = zeros(m,priorsInfo.extractCellNum*priorsInfo.extractCellNum*31);
for i = 1:m
F(i,:) = reshape(...
vl_hog(single(images{i}(extractWindow(3):extractWindow(4),extractWindow(1):extractWindow(2))),extractCellSize),...
[1,priorsInfo.extractCellNum*priorsInfo.extractCellNum*31]);
end;
for i = 1:2
predicted(:,i) = predict(priorModel.B{i},F);
end;
predicted_vote = mean(predicted,2);
ind = find(predicted(:,1) .* predicted(:,2) < 0);
predicted_vote(ind) = 0;
ind = find(predicted(:,1) > priorsInfo.predictedVoteThre & predicted(:,2) > priorsInfo.predictedVoteThre);
predicted_vote(ind) = max(predicted(ind,:),[],2);
ind = find(predicted(:,1) < -priorsInfo.predictedVoteThre & predicted(:,2) < -priorsInfo.predictedVoteThre);
predicted_vote(ind) = min(predicted(ind,:),[],2);
Tr = getTransViaRotateGivenCenter(-predicted_vote,rotationCenter,priorsInfo.rotatorLength);
T = getTransViaMerge(priorsInfo.win_size,Tb,Tr);
for i = 1:m
images{i} = imtransform(ori_images{i},T(i),'XData',[1 priorsInfo.win_size],...
'YData',[1 priorsInfo.win_size]);
end;
end