您的位置:首页 > 其它

人脸识别经典算法二:LBP方法

2014-05-23 10:33 375 查看


人脸识别经典算法二:LBP方法

分类: 计算机视觉2014-04-09
11:18 3942人阅读 评论(8) 收藏 举报

LBP人脸识别局部二值模式

第一篇博文特征脸方法不同,LBP(Local
Binary Patterns,局部二值模式)是提取局部特征作为判别依据的。LBP方法显著的优点是对光照不敏感,但是依然没有解决姿态和表情的问题。不过相比于特征脸方法,LBP的识别率已经有了很大的提升。在[1]的文章里,有些人脸库的识别率已经达到了98%+。

1、LBP特征提取

最初的LBP是定义在像素3x3邻域内的,以邻域中心像素为阈值,将相邻的8个像素的灰度值与其进行比较,若周围像素值大于中心像素值,则该像素点的位置被标记为1,否则为0。这样,3x3邻域内的8个点经比较可产生8位二进制数(通常转换为十进制数即LBP码,共256种),即得到该邻域中心像素点的LBP值,并用这个值来反映该区域的纹理信息。如下图所示:



用比较正式的公式来定义的话:



其中

代表3x3邻域的中心元素,它的像素值为ic,ip代表邻域内其他像素的值。s(x)是符号函数,定义如下:



LBP的改进版本

(1)圆形LBP算子

基本的 LBP算子的最大缺陷在于它只覆盖了一个固定半径范围内的小区域,这显然不能满足不同尺寸和频率纹理的需要。为了适应不同尺度的纹理特征,并达到灰度和旋转不变性的要求,Ojala等对 LBP 算子进行了改进,将 3×3邻域扩展到任意邻域,并用圆形邻域代替了正方形邻域,改进后的 LBP 算子允许在半径为 R 的圆形邻域内有任意多个像素点。从而得到了诸如半径为R的圆形区域内含有P个采样点的LBP算子。比如下图定了一个5x5的邻域:



上图内有八个黑色的采样点,每个采样点的值可以通过下式计算:



其中

为邻域中心点,

为某个采样点。通过上式可以计算任意个采样点的坐标,但是计算得到的坐标未必完全是整数,所以可以通过双线性插值来得到该采样点的像素值:



(2)LBP等价模式

一个LBP算子可以产生不同的二进制模式,对于半径为R的圆形区域内含有P个采样点的LBP算子将会产生2^P种模式。很显然,随着邻域集内采样点数的增加,二进制模式的种类是急剧增加的。例如:5×5邻域内20个采样点,有220=1,048,576种二进制模式。如此多的二值模式无论对于纹理的提取还是对于纹理的识别、分类及信息的存取都是不利的。同时,过多的模式种类对于纹理的表达是不利的。例如,将LBP算子用于纹理分类或人脸识别时,常采用LBP模式的统计直方图来表达图像的信息,而较多的模式种类将使得数据量过大,且直方图过于稀疏。因此,需要对原始的LBP模式进行降维,使得数据量减少的情况下能最好的代表图像的信息。

为了解决二进制模式过多的问题,提高统计性,Ojala提出了采用一种“等价模式”(Uniform Pattern)来对LBP算子的模式种类进行降维。Ojala等认为,在实际图像中,绝大多数LBP模式最多只包含两次从1到0或从0到1的跳变。因此,Ojala将“等价模式”定义为:当某个LBP所对应的循环二进制数从0到1或从1到0最多有两次跳变时,该LBP所对应的二进制就称为一个等价模式类。如00000000(0次跳变),00000111(只含一次从0到1的跳变),10001111(先由1跳到0,再由0跳到1,共两次跳变)都是等价模式类。除等价模式类以外的模式都归为另一类,称为混合模式类,例如10010111(共四次跳变)。比如下图给出了几种等价模式的示意图。



通过这样的改进,二进制模式的种类大大减少,而不会丢失任何信息。模式数量由原来的2P种减少为 P ( P-1)+2种,其中P表示邻域集内的采样点数。对于3×3邻域内8个采样点来说,二进制模式由原始的256种减少为58种,这使得特征向量的维数更少,并且可以减少高频噪声带来的影响。这几段摘自[2]。

通过上述方法,每个像素都会根据邻域信息得到一个LBP值,如果以图像的形式显示出来可以得到下图,明显LBP对光照有较强的鲁棒性。



2、LBP特征匹配

如果将以上得到的LBP值直接用于人脸识别,其实和不提取LBP特征没什么区别,会造成计算量准确率等一系列问题。文献[1]中,将一副人脸图像分为7x7的子区域(如下图),并在子区域内根据LBP值统计其直方图,以直方图作为其判别特征。这样做的好处是在一定范围内避免图像没完全对准的情况,同时也对LBP特征做了降维处理。



对于得到的直方图特征,有多种方法可以判别其相似性,假设已知人脸直方图为Mi​,待匹配人脸直方图为Si,那么可以通过:

(1)直方图交叉核方法



该方法的介绍在博文:Histogram
intersection(直方图交叉核,Pyramid Match Kernel)

(2)卡方统计方法



该方法的介绍在博文:卡方检验(Chi
square statistic)

参考文献:

[1]Timo Ahonen, Abdenour Hadid:Face Recognition with Local Binary Patterns

[2]目标检测的图像特征提取之(二)LBP特征


图像分析:LBP特征解析与代码

分类: 算法与理论研究 图像分析专栏2013-08-29
11:00 542人阅读 评论(0) 收藏 举报

LBP

LBP(Local Binary Patterns),即局部二值模式,是一种描述图像局部空间结构的非参数算子。芬兰Oulu大学的T.Ojala等人于1996年提出这个算子用来分析图像纹理特征,并且描述了它在纹理分类中的强区分能力。LBP算子定义为一种灰度尺度不变的纹理算子,是从局部邻域纹理的普通定义得来的。

基本思想是:用中心像素的灰度值作为阈值,与它的邻域相比较得到的二进制码来表述局部纹理特征。

在纹理分析方面,LBP算子是最好的纹理描述符之一,它的主要优点有以下几点:

Ø 通过它的定义可知,LBP算子的灰度尺度不随任何单一变换而变化,因此灰度尺度的鲁棒性好,也就是光照条件下的鲁棒性好;

Ø 计算速度快。由于它可以通过在小邻域内进行比较操作得到,使得在复杂的实时条件下分析图像成为可能;
Ø 由于LBP算子是一种无参数(Non-Parametric)的方法,在应用过程中不需要对它的分布进行预先假设。

_____________________________________________________________________________________



[plain] view
plaincopy

%LBP returns the local binary pattern image or LBP histogram of an image.

% J = LBP(I,R,N,MAPPING,MODE) returns either a local binary pattern

% coded image or the local binary pattern histogram of an intensity

% image I. The LBP codes are computed using N sampling points on a

% circle of radius R and using mapping table defined by MAPPING.

% See the getmapping function for different mappings and use 0 for

% no mapping. Possible values for MODE are

% 'h' or 'hist' to get a histogram of LBP codes

% 'nh' to get a normalized histogram

% Otherwise an LBP code image is returned.

%

% J = LBP(I) returns the original (basic) LBP histogram of image I

%

% J = LBP(I,SP,MAPPING,MODE) computes the LBP codes using n sampling

% points defined in (n * 2) matrix SP. The sampling points should be

% defined around the origin (coordinates (0,0)).

%

% Examples

% --------

% I=imread('rice.png');

% mapping=getmapping(8,'u2');

% H1=LBP(I,1,8,mapping,'h'); %LBP histogram in (8,1) neighborhood

% %using uniform patterns

% subplot(2,1,1),stem(H1);

%

% H2=LBP(I);

% subplot(2,1,2),stem(H2);

%

% SP=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];

% I2=LBP(I,SP,0,'i'); %LBP code image using sampling points in SP

% %and no mapping. Now H2 is equal to histogram

% %of I2.

function result = lbp(varargin) % image,radius,neighbors,mapping,mode)

% Version 0.3.2

% Authors: Marko Heikkil�and Timo Ahonen

% Changelog

% Version 0.3.2: A bug fix to enable using mappings together with a

% predefined spoints array

% Version 0.3.1: Changed MAPPING input to be a struct containing the mapping

% table and the number of bins to make the function run faster with high number

% of sampling points. Lauge Sorensen is acknowledged for spotting this problem.

% Check number of input arguments.

error(nargchk(1,5,nargin));

image=varargin{1};

d_image=double(image);

if nargin==1

spoints=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];

neighbors=8;

mapping=0;

mode='h';

end

if (nargin == 2) && (length(varargin{2}) == 1)

error('Input arguments');

end

if (nargin > 2) && (length(varargin{2}) == 1)

radius=varargin{2};

neighbors=varargin{3};

spoints=zeros(neighbors,2);

% Angle step.

a = 2*pi/neighbors;

for i = 1:neighbors

spoints(i,1) = -radius*sin((i-1)*a);

spoints(i,2) = radius*cos((i-1)*a);

end

if(nargin >= 4)

mapping=varargin{4};

if(isstruct(mapping) && mapping.samples ~= neighbors)

error('Incompatible mapping');

end

else

mapping=0;

end

if(nargin >= 5)

mode=varargin{5};

else

mode='h';

end

end

if (nargin > 1) && (length(varargin{2}) > 1)

spoints=varargin{2};

neighbors=size(spoints,1);

if(nargin >= 3)

mapping=varargin{3};

if(isstruct(mapping) && mapping.samples ~= neighbors)

error('Incompatible mapping');

end

else

mapping=0;

end

if(nargin >= 4)

mode=varargin{4};

else

mode='h';

end

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^neighbors;

% Initialize the result matrix with zeros.

result=zeros(dy+1,dx+1);

%Compute the LBP code image

for i = 1:neighbors

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

%Apply mapping if it is defined

if isstruct(mapping)

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

end

if (strcmp(mode,'h') || strcmp(mode,'hist') || strcmp(mode,'nh'))

% Return with LBP histogram if mode equals 'hist'.

result=hist(result(:),0:(bins-1));

if (strcmp(mode,'nh'))

result=result/sum(result);

end

else

%Otherwise return a matrix of unsigned integers

if ((bins-1)<=intmax('uint8'))

result=uint8(result);

elseif ((bins-1)<=intmax('uint16'))

result=uint16(result);

else

result=uint32(result);

end

end

end

[plain] view
plaincopy

%GETMAPPING returns a structure containing a mapping table for LBP codes.

% MAPPING = GETMAPPING(SAMPLES,MAPPINGTYPE) returns a structure containing a mapping table for

% LBP codes in a neighbourhood of SAMPLES sampling points. Possible values for MAPPINGTYPE are

% 'u2' for uniform LBP

% 'ri' for rotation-invariant LBP

% 'riu2' for uniform rotation-invariant LBP.

%

% Example:

% I=imread('rice.tif');

% MAPPING=getmapping(16,'riu2');

% LBPHIST=lbp(I,2,16,MAPPING,'hist');

% Now LBPHIST contains a rotation-invariant uniform LBP histogram in a (16,2) neighbourhood.

%

function mapping = getmapping(samples,mappingtype)

% Version 1.0 beta

% Authors: Marko Heikkil?and Timo Ahonen

% Editor: LinJianmin - Huaqiao University

% Email: jianmin1990@outlook.com

table = 0:2^samples-1;

newMax = 0; %number of patterns in the resulting LBP code

index = 0;

if strcmp(mappingtype,'u2') %Uniform 2

newMax = samples*(samples-1) + 3;

for i = 0:2^samples-1

j = bitset(bitshift(i,1,samples),1,bitget(i,samples)); %rotate left

numt = sum(bitget(bitxor(i,j),1:samples)); %number of 1->0 and 0->1 transitions in binary string

%x is equal to the number of 1-bits in XOR(x,Rotate left(x))

if numt <= 2

table(i+1) = index;

index = index + 1;

else

table(i+1) = newMax - 1;

end

end

end

if strcmp(mappingtype,'ri') %Rotation invariant

tmpMap = zeros(2^samples,1) - 1;

for i = 0:2^samples-1

rm = i;

r = i;

for j = 1:samples-1

r = bitset(bitshift(r,1,samples),1,bitget(r,samples)); %rotate

%left

if r < rm

rm = r;

end

end

if tmpMap(rm+1) < 0

tmpMap(rm+1) = newMax;

newMax = newMax + 1;

end

table(i+1) = tmpMap(rm+1);

end

end

if strcmp(mappingtype,'riu2') %Uniform & Rotation invariant

newMax = samples + 2;

for i = 0:2^samples - 1

j = bitset(bitshift(i,1,samples),1,bitget(i,samples)); %rotate left

numt = sum(bitget(bitxor(i,j),1:samples));

if numt <= 2

table(i+1) = sum(bitget(i,1:samples));

else

table(i+1) = samples+1;

end

end

end

mapping.table=table;

mapping.samples=samples;

mapping.num=newMax;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: