局部渐变图案实现
Local Gradient Pattern Implementation
我正在尝试理解局部梯度模式,它在局部梯度模式 - 一种新颖的面部特征表示中有所描述
表情识别.
有一个计算像素新值的例子如下:
我看到中心像素(即 25)的 Pattern-1
值为 10
,Pattern-2
值为 01
。我有几个问题。
- 中心像素的新值是多少?
- LGP和LBP有什么关系?
- 是否有使用 LGP 转换二维矩阵的伪代码(Python 首选)?
What will be the new value of that center pixel?
这取决于编码方案。参考论文没有清楚地解释局部梯度模式是如何编码的。一种可能的编码是:
哪里
如果将示例的强度值引入模式代码结果上方的表达式中:
请注意,使用不同编码的效果是对直方图 bin 进行重新排序,但这不会对分类准确性产生影响。
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]
演示
In [31]: patch = np.array([[18, 25, 14],
...: [85, 25, 86],
...: [45, 65, 14]])
...:
In [32]: LGP_codes(patch)
Out[32]: array([[9]])
我正在尝试理解局部梯度模式,它在局部梯度模式 - 一种新颖的面部特征表示中有所描述 表情识别.
有一个计算像素新值的例子如下:
我看到中心像素(即 25)的 Pattern-1
值为 10
,Pattern-2
值为 01
。我有几个问题。
- 中心像素的新值是多少?
- LGP和LBP有什么关系?
- 是否有使用 LGP 转换二维矩阵的伪代码(Python 首选)?
What will be the new value of that center pixel?
这取决于编码方案。参考论文没有清楚地解释局部梯度模式是如何编码的。一种可能的编码是:
哪里
如果将示例的强度值引入模式代码结果上方的表达式中:
请注意,使用不同编码的效果是对直方图 bin 进行重新排序,但这不会对分类准确性产生影响。
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]
演示
In [31]: patch = np.array([[18, 25, 14],
...: [85, 25, 86],
...: [45, 65, 14]])
...:
In [32]: LGP_codes(patch)
Out[32]: array([[9]])