Possible Duplicate:
Local Binary Pattern in MATLAB
I would like to implement uniform LBP. This is the definiton given by wikipedia for uniform LBP.
A local binary pattern is called uniform if the binary pattern
contains at most two bitwise transitions from 0 to 1 or vice versa
when the bit pattern is traversed circularly. For example, the
patterns 00000000 (0 transitions), 01110000 (2 transitions) and
11001111 (2 transitions) are uniform whereas the patterns 11001001 (4
transitions) and 01010010 (6 transitions) are not. In the computation
of the LBP labels, uniform patterns are used so that there is a
separate label for each uniform pattern and all the non-uniform
patterns are labeled with a single label. For example, when using
(8,R) neighborhood, there are a total of 256 patterns, 58 of which are
uniform, which yields in 59 different labels.
I have written code for LBP but not sure how to convert it to a uniform LBP. Below is the code for LBP.
for i=2:m-1
for j=2:n-1
J0=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>J0;
I3(i-1,j)=I2(i-1,j)>J0;
I3(i-1,j+1)=I2(i-1,j+1)>J0;
I3(i,j+1)=I2(i,j+1)>J0;
I3(i+1,j+1)=I2(i+1,j+1)>J0;
I3(i+1,j)=I2(i+1,j)>J0;
I3(i+1,j-1)=I2(i+1,j-1)>J0;
I3(i,j-1)=I2(i,j-1)>J0;
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
end
end
figure,imshow(uint8(LBP))
Any help would be appreciated. I am using MATLAB.
Steps
LBP.LBPinto the 59 labels using the table.labeled = table(LBP) % this is called table lookup or MATLAB indexing.Suggestions (although not necessary for implementation)
I3(1), I3(2), ... I3(8)because they will be reassigned each time you move on to the next center pixel(i,j).function table = BitwiseToLBP % we reserve label 0 for non-uniform table = zeros(1, 256); nextLabel = 1; for k = 1:256, bits = bitand(k, 2.^(0:7)) > 0; if IsUniformLBP(bits), table(k) = nextLabel; nextLabel = nextLabel + 1; else table(k) = 0; end end endfunction IsUniformLBP(bits) nnz(diff(bits([1:end, 1]))) == 2; end