我正在尝试手动编码Ojala的Local Binary Pattern算法,但从Matlab的 extractLBPFeatures 函数获得了不同的结果。您能告诉我我错过了哪些要点吗?您可以在下面找到LBP的详细信息;
让我解释一下我的MATLAB代码;
% LBP Algorithm
sample = [ %SAMPLE PATTERN
119 115 94 59 46;
115 113 104 87 54;
110 109 102 99 76;
121 114 101 99 96;
127 123 112 101 101;
131 126 118 107 97;
136 127 121 112 99
];
original = extractLBPFeatures(uint8(sample)); %MATLAB LBP FUNC.
manual = manualLBP(sample); %MANUAL LBP FUNC.
function result = manualLBP(sample)
unipatterns = [ %UNIPATTERNS (count:58) known by Ojala's paper.
0,1,2,3,4,6,7,...
8,12,14,15,16,24,28,...
30,31,32,48,56,60,62,...
63,64,96,112,120,124,126,...
127,128,129,131,135,143,159,...
191,192,193,195,199,207,223,...
224,225,227,231,239,240,241,...
243,247,248,249,251,252,253,...
254,255
];
m=size(sample,1);
n=size(sample,2);
for i=2:m-1
for j=2:n-1
c=sample(i,j);
I3(1,1)=sample(i-1,j-1)>c;
I3(1,2)=sample(i-1,j)>c;
I3(1,3)=sample(i-1,j+1)>c;
I3(2,3)=sample(i,j+1)>c;
I3(3,3)=sample(i+1,j+1)>c;
I3(3,2)=sample(i+1,j)>c;
I3(3,1)=sample(i+1,j-1)>c;
I3(2,1)=sample(i,j-1)>c;
LBP(i-1,j-1) = I3(1,1)*2^7 + I3(1,2)*2^6 + I3(1,3)*2^5 + I3(2,3)*2^4 + I3(3,3)*2^3+I3(3,2)*2^2 + I3(3,1)*2^1 + I3(2,1)*2^0;
end
end
LBPtmp = LBP(:); %SERIALIZE LBP. (MATIX TO VECTOR)
for i=1:size(unipatterns,2)
result(i) = sum(LBPtmp == unipatterns(i));
end
result(59) = size(LBPtmp,1)-sum(result(:)~=0); % LBP(59) = PIXELCOUNT - UNIPATTERN_COUNT
result = result/norm(result); %L2 NORMALIZATION
end
我没有使用任何参数,例如CellSize,Normalization等。只是试图认识到两个代码之间的区别是什么。