如何实现统一LBP?

发布于 2024-12-07 10:04:46 字数 1177 浏览 0 评论 0原文

可能的重复:
MATLAB 中的本地二进制模式

我想实现统一的 LBP。这是维基百科给出的统一 LBP 的定义。

如果二进制模式是一致的,则局部二进制模式被称为统一的 最多包含两个从 0 到 1 的按位转换,反之亦然 当位模式循环遍历时。例如, 模式 00000000(0 个转换)、01110000(2 个转换)和 11001111(2 个过渡)是均匀的,而图案 11001001(4 转换)和 01010010(6 个转换)不是。在计算中 在 LBP 标签中,使用统一的模式,以便有 每个统一图案和所有非统一图案都有单独的标签 图案用单个标签标记。例如,当使用 (8,R)邻域,共有256种模式,其中58种是 统一,产生 59 种不同的标签。

我已经为 LBP 编写了代码,但不确定如何将其转换为统一的 LBP。下面是 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))

任何帮助将不胜感激。我正在使用 MATLAB。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的夜不怕黑 2024-12-14 10:04:46

步骤

  1. 下一步是为存储在 LBP 中的值构建一个查找表。
    • 查找表将 256 种可能的组合映射到 59 个不同的标签。
    • 如果速度不重要,可以使用 for 循环构建表格。
  2. 使用表格将 LBP 映射到 59 个标签。
    • labeled = table(LBP) % 这称为表查找或 MATLAB 索引。
  3. 使用这 59 个标签执行任何其他工作。

建议(虽然对于实现来说不是必需的)

  1. I3 不需要使用 2D 矩阵。当前像素的八个邻居是您正在处理的当前像素的本地像素;因此您可以简单地将它们分配给 I3(1), I3(2), ... I3(8) 因为每次您移动到下一个中​​心像素 ( 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

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
月亮邮递员 2024-12-14 10:04:46

我尝试了这段代码:

 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文