1.LBP算子
function hst = LBP(X)
%Returns LBP histogram (256 bins) of picture X.
%
% 1 2 4
% weights = 128 0 8
% 64 32 16
%
%the size of X must be at least 3x3 pixels
D = size(X);
sx = D(2);
sy = D(1);
Xi = zeros(sy+2,sx+2);
Xi(2:sy+1,2:sx+1) = X;
Xi1 = zeros(sy+2,sx+2);Xi2 = zeros(sy+2,sx+2);Xi3 = zeros(sy+2,sx+2);Xi4= zeros(sy+2,sx+2);
Xi5 = zeros(sy+2,sx+2);Xi6 = zeros(sy+2,sx+2);Xi7 = zeros(sy+2,sx+2);Xi8 = zeros(sy+2,sx+2);
Xi1(3:sy+2,3:sx+2) = X;
Xi2(3:sy+2,2:sx+1) = X;
Xi3(3:sy+2,1:sx) = X;
Xi4(2:sy+1,1:sx) = X;
Xi5(1:sy,1:sx) = X;
Xi6(1:sy,2:sx+1) = X;
Xi7(1:sy,3:sx+2) = X;
Xi8(2:sy+1,3:sx+2) = X;
Xi= (Xi1>=Xi)+2*(Xi2>=Xi)+4*(Xi3>=Xi)+8*(Xi4>=Xi)+16*(Xi5>=Xi)+32*(Xi6>=Xi)+64*(Xi7>=Xi)+128*(Xi8>=Xi);
X=Xi(3:sy,3:sx);
hst=sum(hist(X,0:255)');
2. LBP_riu81算子
function hst = LBP_riu81(X)
%Returns a rotation invariant LBP (uniform patterns) histogram (10 bins) of
%picture X.
%the size of picture X must be at least 3x3 pixels
patternMap = [1 2 2 3 2 10 3 4 2 10 10 10 3 10 4 5 2 10 10 10 10 10 10 10 3 10 10 10 4 10 5 6 ...
2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 3 10 10 10 10 10 10 10 4 10 10 10 5 10 6 7 ...
2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
3 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 4 10 10 10 10 10 10 10 5 10 10 10 6 10 7 8 ...
2 3 10 4 10 10 10 5 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 7 ...
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 8 ...
3 4 10 5 10 10 10 6 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 8 ...
4 5 10 6 10 10 10 7 10 10 10 10 10 10 10 8 5 6 10 7 10 10 10 8 6 7 10 8 7 8 8 9];
w1 = (1/sqrt(2))^2;
w2 = (1-1/sqrt(2))*(1/sqrt(2));
D = size(X);
sy = D(1);
sx = D(2);
Xi = zeros(sy+2,sx+2);
Xi(2:sy+1,2:sx+1) = X;
Xi1 = zeros(sy+2,sx+2);Xi2 = zeros(sy+2,sx+2);Xi3 = zeros(sy+2,sx+2);Xi4= zeros(sy+2,sx+2);
Xi5 = zeros(sy+2,sx+2);Xi6 = zeros(sy+2,sx+2);Xi7 = zeros(sy+2,sx+2);Xi8 = zeros(sy+2,sx+2);
p1 = zeros(sy+2,sx+2);p2 = zeros(sy+2,sx+2);p3 = zeros(sy+2,sx+2);
p4 = zeros(sy+2,sx+2);p5 = zeros(sy+2,sx+2);p6 = zeros(sy+2,sx+2);
p7 = zeros(sy+2,sx+2);p8 = zeros(sy+2,sx+2);p9 = zeros(sy+2,sx+2);
p1(3:sy+2,3:sx+2) = X ;
p2(3:sy+2,2:sx+1) = w2*double(X) ;
p3(3:sy+2,1:sx) = X ;
p4(2:sy+1,3:sx+2) = w2*double(X) ;
p5(2:sy+1,2:sx+1) = (1-1/sqrt(2))^2*double(X) ;
p6(2:sy+1,1:sx) = w2*double(X) ;
p7(1:sy,3:sx+2) = X ;
p8(1:sy,2:sx+1) = w2*double(X) ;
p9(1:sy,1:sx) = X ;
Xi1 = w1*p1+ p2+p4 + p5 + 0.000001; %Xi1 to the right and down from X
Xi2(3:sy+2,2:sx+1) = X;
Xi3 = w1*p3 + p2 + p6 + p5 + 0.000001;
Xi4(2:sy+1,1:sx) = X;
Xi5 = w1*p9 + p8 + p6 + p5 + 0.000001;
Xi6(1:sy,2:sx+1) = X;
Xi7 = w1*p7 + p8 + p4 + p5 + 0.000001;
Xi8(2:sy+1,3:sx+2) = X;
Xi= (Xi4>=Xi)+2*(Xi5>=Xi)+4*(Xi6>=Xi)+8*(Xi7>=Xi)+16*(Xi8>=Xi)+32*(Xi1>=Xi)+64*(Xi2>=Xi)+128*(Xi3>=Xi);
X=Xi(3:sy,3:sx);
x=0:255;
n=hist(X,x);
thst=sum(n');
hst=zeros(1,10);
for I=1:256
hst(patternMap(I))=hst(patternMap(I))+thst(I);
end
3 . LBP_riu162算子
function hst = LBP_riu162(X)
%Returns a rotation invariant LBP (uniform patterns) histogram of picture X.
%number of pixels = 16 => 18 bins
%predicate =2
%size of picture X must be at least 5X5 pixels
w1 = (cos(pi/8)*2-1)*(sin(pi/8)*2);
w2 = (cos(pi/8)*2-1)*(1-sin(pi/8)*2);
w3 = (2-cos(pi/8)*2)*(sin(pi/8)*2);
w4 = (2-cos(pi/8)*2)*(1-sin(pi/8)*2);
w5 = (cos(pi/4)*2-1)*(sin(pi/4)*2-1);
w6 = (2-cos(pi/4)*2)*(sin(pi/4)*2-1);
w7 = (2-cos(pi/4)*2)*(2-sin(pi/4)*2);
D = size(X);
sx = D(2);
sy = D(1);
p1 = zeros(sy+4,sx+4);p2 = zeros(sy+4,sx+4);p3 = zeros(sy+4,sx+4);
p4 = zeros(sy+4,sx+4);p5 = zeros(sy+4,sx+4);p6 = zeros(sy+4,sx+4);
p7 = zeros(sy+4,sx+4);p8 = zeros(sy+4,sx+4);p9 = zeros(sy+4,sx+4);
p10 = zeros(sy+4,sx+4);
pc = zeros(sy+4,sx+4);
pc(3:sy+2,3:sx+2) = X ;
%upper left corner
p1(5:sy+4,5:sx+4) = X ;
p2(5:sy+4,4:sx+3) = X ;
p3(4:sy+3,5:sx+4) = X ;
p4(4:sy+3,4:sx+3) = X ;
p5(5:sy+4,3:sx+2) = X ;
p6(4:sy+3,3:sx+2) = X ;
p7(3:sy+2,5:sx+4) = X ;
p8(3:sy+2,4:sx+3) = X ;
Xi1 = p7 >=pc; %Xi1 to the left from center
Xi2 = (w1*p3+ w3*p4 + w2*p7 + w4*p8 + 0.00001)>=pc ;
tmp2 = (Xi1~=Xi2);
Xi3 = (w5*p1+ w6*(p2 + p3) + w7*p4 + 0.00001)>=pc ;
Xi = Xi1 + Xi2 + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p2+ w3*p4 + w2*p5 + w4*p6 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
%upper right corner
p1(5:sy+4,2:sx+1) = X ;
p2(5:sy+4,1:sx) = X ;
p3(4:sy+3,2:sx+1) = X ;
p4(4:sy+3,1:sx) = X ;
p9(3:sy+2,2:sx+1) = X ;
p10(3:sy+2,1:sx) = X ;
Xi3 = p5 >= pc; %Xi5 up from center
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p1+ w3*p3 + w2*p5 + w4*p6 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi3 = (w5*p2+ w6*(p1 + p4) + w7*p3 + 0.00001)>=pc ;
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p4+ w3*p3 + w2*p10 + w4*p9 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
%lower right corner
p1(2:sy+1,2:sx+1) = X ;
p2(2:sy+1,1:sx) = X ;
p3(1:sy,2:sx+1) = X ;
p4(1:sy,1:sx) = X ;
p5(2:sy+1,3:sx+2) = X ;
p6(1:sy,3:sx+2) = X ;
Xi3 = (p10>=pc); %Xi5 to the right from center
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p2+ w3*p1 + w2*p10 + w4*p9 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi3 = (w5*p4+ w6*(p2 + p3) + w7*p1 + 0.00001)>=pc ;
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p3+ w3*p1 + w2*p6 + w4*p5 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
%lower left corner
p1(2:sy+1,5:sx+4) = X ;
p2(2:sy+1,4:sx+3) = X ;
p3(1:sy,5:sx+4) = X ;
p4(1:sy,4:sx+3) = X ;
Xi3 = p6>=pc; %Xi5 down from center
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p4+ w3*p2 + w2*p6 + w4*p5 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi3 = (w5*p3+ w6*(p1 + p4) + w7*p2 + 0.00001)>=pc ;
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi2 = (w1*p1+ w3*p2 + w2*p7 + w4*p8 + 0.00001)>=pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3)+ (Xi2~=Xi1);
Xi(tmp2>2)=17;
X=Xi(5:sy,5:sx);
hst=sum(hist(X,0:17)');
3 . LBP_riu243算子
function hst = LBP_riu243(X)
%Returns a rotation invariant LBP (uniform patterns) histogram of picture X.
%Number of interpolated pixels = 24 -> 26 bins
%Predicate = 3.
%
%the size of X must be at least 7X7 pixels
w1 = (cos(pi/12)*3-2)*(sin(pi/12)*3);
w2 = (3-cos(pi/12)*3)*(sin(pi/12)*3);
w3 = (cos(pi/12)*3-2)*(1-sin(pi/12)*3);
w4 = (3-cos(pi/12)*3)*(1-sin(pi/12)*3);
w5 = (cos(pi/6)*3-2)/2;
w6 = (3-cos(pi/6)*3)/2;
w7 = (3-cos(pi/8)*3)^2;
w8 = (cos(pi/8)*3-2)*(3-cos(pi/8)*3);
w9 = (cos(pi/8)*3-2)^2;
D = size(X);
sy=D(1);
sx=D(2);
Xi = zeros(sy+6,sx+6);
p1 = zeros(sy+6,sx+6);p2 = zeros(sy+6,sx+6);p3 = zeros(sy+6,sx+6);
p4 = zeros(sy+6,sx+6);p5 = zeros(sy+6,sx+6);p6 = zeros(sy+6,sx+6);
p7 = zeros(sy+6,sx+6);p8 = zeros(sy+6,sx+6);
pc = zeros(sy+6,sx+6);
pc(4:sy+3,4:sx+3) = X ;
%left
p5(4:sy+3,7:sx+6) = X ;
p6(4:sy+3,6:sx+5) = X ;
p1(5:sy+4,7:sx+6) = X ;
p2(5:sy+4,6:sx+5) = X ;
Xi1 = p5 >=pc; %Xi1 to the left from center
Xi2 = (w1*p1+ w2*p2 + w3*p5 + w4*p6)>=pc ;
tmp2 = (Xi1~=Xi2);
p3(6:sy+5,7:sx+6) = X ;
p4(6:sy+5,6:sx+5) = X ;
Xi3 = (w5*(p1+p3) + w6*(p2+p4)) >= pc ;
Xi = Xi1 + Xi2 + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
p1(7:sy+6,7:sx+6) = X ;
p2(7:sy+6,6:sx+5) = X ;
Xi2 = (w7*p1 + w8*(p2+p3) + w9*p4) >= pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
p1(7:sy+6,5:sx+4) = X ;
p3(6:sy+5,5:sx+4) = X ;
Xi3 = (w5*(p1+p2) + w6*(p3+p4)) >= pc ;
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
p2(7:sy+6,4:sx+3) = X ;
p4(6:sy+5,4:sx+3) = X ;
Xi2 = (w1*p1 + w2*p3 + w3*p2 + w4*p4) >= pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
Xi3 = p2 >= pc ; %up
Xi = Xi + Xi3;
tmp2 = tmp2 + (Xi2~=Xi3);
p1(7:sy+6,3:sx+2) = X ;
p3(6:sy+5,3:sx+2) = X ;
Xi2 = (w1*p1 + w2*p3 + w3*p2 + w4*p4) >= pc ;
Xi = Xi + Xi2;
tmp2 = tmp2 + (Xi2~=Xi3);
p2(7:sy+6,2:sx+1) = X ;
p4(6:sy+
- 1
- 2
前往页