局部梯度模式实现

2024-05-29 04:27:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解Local gradient pattern - A novel feature representation for facial expression recognition中描述的局部梯度模式。在

下面是一个计算像素新值的示例:

pattern calculation

我看到中心像素(25)Pattern-1的值是10,而{}的值是01。我有几个问题。在

  • 中心像素的新值是多少?在
  • LGP与LBP的关系如何?在
  • 有没有使用LGP(Python首选)转换2D矩阵的伪代码?在

Tags: forlocal局部像素中心featurepatternexpression
1条回答
网友
1楼 · 发布于 2024-05-29 04:27:32

What will be the new value of that center pixel?

编码取决于编码方式。参考文献没有清楚地解释局部梯度图案是如何编码的。一种可能的编码方式是:

LGP

在哪里

f(x)

如果将示例的强度值引入图案代码结果上方的表达式中:

code calculation example

请注意,使用不同编码的效果将是对柱状图库进行重新排序,但这不会影响分类精度。在

How LGP is related with LBP?

LGP只是LBP众多变体中的一个。查看this book进行全面回顾。在

Is there any pseudo code for converting a 2D matrix using LGP (Python preferred)?

请尝试以下代码:

import numpy as np

def LGP_codes(img, r=1):
    padded = np.pad(img, (r, r), 'constant')
    a1 = padded[:-2*r, :-2*r]
    b1 = padded[:-2*r, r:-r]
    a2 = padded[:-2*r, 2*r:]
    b2 = padded[r:-r, 2*r:]
    a3 = padded[2*r:, 2*r:]
    b3 = padded[2*r:, r:-r]
    a4 = padded[2*r:, :-2*r]
    b4 = padded[r:-r, :-2*r]
    codes = (a1 >= a3) + 2*(a2 >= a4) + 4*(b1 >= b3) + 8*(b2 >= b4)
    return codes[r:-r, r:-r]

演示

^{pr2}$

相关问题 更多 >

    热门问题