forked from cuijiaxun/FaceRecognitionByMatlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extHarrLikeFeature.m
67 lines (61 loc) · 2.82 KB
/
extHarrLikeFeature.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
% 2017-5-17崔佳勋
% 提取Harr-like特征
% II 积分图像
% HarrLike Harr模板
% baseSize 基准的尺寸大小
%
function FeatureVector=extHarrLikeFeature(II,HarrLike,baseSize)
imgWidth=size(II,2); % 窗口宽度
imgHeight=size(II,1); % 窗口高度
wdiv=1; % 横向间隔 一个像素点为一步
hdiv=1; % 纵向间隔 一个像素点为一步
FeatureVector=[];
Feature=[];
delta=1; %一步为1
for harrCnt=1:length(HarrLike)% 当前采取的Harr-like形式
s=size(HarrLike{harrCnt},1);
t=size(HarrLike{harrCnt},2);
R = s:s:floor(imgHeight/s)*s; % Haar窗口高
C = t:t:floor(imgWidth/t)*t; % Haar窗口宽
NUM = 0; % Haar特征总数
for I = 1:length(R)
for J = 1:length(C)
r = R(I)*hdiv; % Haar窗口高
c = C(J)*wdiv; % Haar窗口宽
nr = imgHeight-r; % 行方向移动个数
nc = imgWidth-c; % 列方向移动个数
for x=1:nc % 第几列
for y=1:nr % 第几行
if (harrCnt==1)
white = II(y,x)+II(y+r,x+c/2)-II(y+r,x)-II(y,x+c/2);
black = II(y,x+c/2)+II(y+r,x+c)-II(y+r,x+c/2)-II(y,x+c);
end
if (harrCnt==2)
white = II(y,x)+II(y+r/2,x+c)-II(y,x+c)-II(y+r/2,x);
black = II(y+r/2,x)+II(y+r,x+c)-II(y+r/2,x+c)-II(y+r,x);
end
if (harrCnt==3)
white = II(y+r,x+c/3)+II(y,x)-II(y,x+c/3)-II(y+r,x)+...
II(y+r,x+c)+II(y,x+2*c/3)-II(y,x+c)-II(y+r,x+2*c/3);
black =2*(II(y+r,x+2*c/3)+II(y,x+c/3)-II(y,x+2*c/3)-II(y+r,x+c/3));
end
if (harrCnt==4)
white = II(y+r/3,x+c)+II(y,x)-II(y+r/3,x)-II(y,x+c)+...
II(y+r,x+c)+II(y+2*r/3,x)-II(y+2*r/3,x+c)-II(y+r,x);
black = 2*(II(y+2*r/3,x+c)+II(y+r/3,x)-II(y+r/3,x+c)-II(y+2*r/3,x));
end
if (harrCnt==5)
white = II(y+r/2,x+c/2)+II(y,x)-II(y+r/2,x)-II(y,x+c/2)...
+II(y+r,x+c)+II(y+r/2,x+c/2)-II(y+r/2,x+c)-II(y+r,x+c/2);
black = II(y+r,x+c/2)+II(y+r/2,x)-II(y+r/2,x+c/2)-II(y+r,x)...
+II(y+r/2,x+c)+II(y,x+c/2)-II(y,x+c)-II(y+r/2,x+c/2);
end
Feature=white-black;
FeatureVector=[FeatureVector;Feature];
NUM = NUM+1;
end
end
end
end
end
end