function result = lbp(face, radius, number)
image = face ;
if size(image,3) > 2
image = rgb2gray(image);
end
d_image=double(image);
r = radius ;
num = number;
spoints = zeros(num,2);
a = 2*pi/num;
for i = 1:num
spoints(i,1) = -r*sin((i-1)*a);
spoints(i,2) = r*cos((i-1)*a);
end
% Determine the dimensions of the input image.
[ysize, xsize] = size(image);
miny=min(spoints(:,1));
maxy=max(spoints(:,1));
minx=min(spoints(:,2));
maxx=max(spoints(:,2));
% Block size, each LBP code is computed within a block of size bsizey*bsizex
bsizey=ceil(max(maxy,0))-floor(min(miny,0))+1;
bsizex=ceil(max(maxx,0))-floor(min(minx,0))+1;
% Coordinates of origin (0,0) in the block
origy=1-floor(min(miny,0));
origx=1-floor(min(minx,0));
% Minimum allowed size for the input image depends
% on the radius of the used LBP operator.
if(xsize < bsizex || ysize < bsizey)
error('Too small input image. Should be at least (2*radius+1) x (2*radius+1)');
end
% Calculate dx and dy;
dx = xsize - bsizex;
dy = ysize - bsizey;
% Fill the center pixel matrix C.
C = image(origy:origy+dy,origx:origx+dx);
d_C = double(C);
% bins = 2^num;
% Initialize the result matrix with zeros.
result=zeros(dy+1,dx+1);
%Compute the LBP code image
for i = 1:num
y = spoints(i,1)+origy;
x = spoints(i,2)+origx;
% Calculate floors, ceils and rounds for the x and y.
fy = floor(y); cy = ceil(y); ry = round(y);
fx = floor(x); cx = ceil(x); rx = round(x);
% Check if interpolation is needed.
if (abs(x - rx) < 1e-6) && (abs(y - ry) < 1e-6)
% Interpolation is not needed, use original datatypes
N = image(ry:ry+dy,rx:rx+dx);
D = N >= C;
else
% Interpolation needed, use double type images
ty = y - fy;
tx = x - fx;
% Calculate the interpolation weights.
w1 = (1 - tx) * (1 - ty);
w2 = tx * (1 - ty);
w3 = (1 - tx) * ty ;
w4 = tx * ty ;
% Compute interpolated pixel values
N = w1*d_image(fy:fy+dy,fx:fx+dx) + w2*d_image(fy:fy+dy,cx:cx+dx) + ...
w3*d_image(cy:cy+dy,fx:fx+dx) + w4*d_image(cy:cy+dy,cx:cx+dx);
D = N >= d_C;
end
% Update the result matrix.
v = 2^(i-1);
result = result + v*D;
end
% figure,imshow(result,[])
mapping = getmapping(num,'u2');
bins = mapping.num;
for i = 1:size(result,1)
for j = 1:size(result,2)
result(i,j) = mapping.table(result(i,j)+1);
end
end
% figure,imshow(result,[])
result=hist(result(:),0:(bins-1));
% result=hist(result(:));
result=result/sum(result);
end
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LBP人脸识别(最近邻分类器) (804个子文件)
3.bmp 11KB
7.bmp 11KB
9.bmp 11KB
1.bmp 11KB
6.bmp 11KB
2.bmp 11KB
7.bmp 11KB
1.bmp 11KB
5.bmp 11KB
10.bmp 11KB
8.bmp 11KB
1.bmp 11KB
8.bmp 11KB
2.bmp 11KB
3.bmp 11KB
2.bmp 11KB
7.bmp 11KB
6.bmp 11KB
8.bmp 11KB
7.bmp 11KB
10.bmp 11KB
2.bmp 11KB
6.bmp 11KB
7.bmp 11KB
8.bmp 11KB
4.bmp 11KB
1.bmp 11KB
1.bmp 11KB
1.bmp 11KB
6.bmp 11KB
3.bmp 11KB
8.bmp 11KB
1.bmp 11KB
10.bmp 11KB
6.bmp 11KB
5.bmp 11KB
1.bmp 11KB
3.bmp 11KB
7.bmp 11KB
3.bmp 11KB
1.bmp 11KB
2.bmp 11KB
6.bmp 11KB
1.bmp 11KB
4.bmp 11KB
5.bmp 11KB
5.bmp 11KB
6.bmp 11KB
7.bmp 11KB
7.bmp 11KB
9.bmp 11KB
4.bmp 11KB
10.bmp 11KB
5.bmp 11KB
2.bmp 11KB
7.bmp 11KB
9.bmp 11KB
5.bmp 11KB
7.bmp 11KB
10.bmp 11KB
9.bmp 11KB
10.bmp 11KB
5.bmp 11KB
10.bmp 11KB
2.bmp 11KB
5.bmp 11KB
4.bmp 11KB
8.bmp 11KB
1.bmp 11KB
4.bmp 11KB
5.bmp 11KB
4.bmp 11KB
5.bmp 11KB
6.bmp 11KB
4.bmp 11KB
10.bmp 11KB
9.bmp 11KB
3.bmp 11KB
2.bmp 11KB
9.bmp 11KB
2.bmp 11KB
4.bmp 11KB
1.bmp 11KB
10.bmp 11KB
3.bmp 11KB
6.bmp 11KB
1.bmp 11KB
3.bmp 11KB
9.bmp 11KB
5.bmp 11KB
8.bmp 11KB
6.bmp 11KB
9.bmp 11KB
3.bmp 11KB
10.bmp 11KB
5.bmp 11KB
2.bmp 11KB
10.bmp 11KB
9.bmp 11KB
4.bmp 11KB
共 804 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
- Villain1107242022-05-07你好,函数knnclassify是怎么定义的,运行的时候显示无法识别
- huanghuaxjau2019-06-02还不错哦,比较好用囊萤映雪的萤2019-06-04哈哈,谢谢哦!
囊萤映雪的萤
- 粉丝: 173
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功