开发者

How to implement Uniform LBP? [duplicate]

开发者 https://www.devze.com 2023-04-09 16:11 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Local Binary Pattern in MATLAB
This question already has answers here: Closed 11 years ago.

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 la开发者_如何学Gobeled 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

  1. Your next step is to construct a lookup table for the values that are stored into LBP.
    • The lookup table maps the 256 possible combinations into 59 different labels.
    • If speed is not important, the table can be built with a for-loop.
  2. Map LBP into the 59 labels using the table.
    • labeled = table(LBP) % this is called table lookup or MATLAB indexing.
  3. Perform any additional work with those 59 labels.

Suggestions (although not necessary for implementation)

  1. There is no need to use a 2D matrix for I3. The eight neighbors of the current pixel are local to the current pixel you are processing; therefore you can simply assign them to 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
end

function IsUniformLBP(bits)
    nnz(diff(bits([1:end, 1]))) == 2;
end


I tried this code:

 sum = abs(I3(k-1,l-1)-I3(k-1,l))+ abs(I3(k-1,l)-I3(k-1,l+1))+ abs(I3(k-1,l+1)-I3(k,l+1))+ abs(I3(k,l+1)-I3(k+1,l+1))+abs(I3(k+1,l+1)-I3(k+1,l))+abs(I3(k+1,l)-I3(k+1,l-1))+abs(I3(k+1,l-1)-I3(k,l-1));
    if(sum <=2)
            UniformHist = [UniformHist Hist];
    end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号