Blu*_*Bee 1 c image-processing pattern-matching feature-extraction computer-vision
我在C中实施统一的LBP.但我对这个概念感到困惑.我已经实施了LBP.假设我有512*512尺寸的图像.在LBP之后它将是510*510.现在如何从这个LBP图像中获得256个像素/像素.
for(i=1; i < image_src->width - 1; i++)
{
for(j=1; j < image_src->height - 1; j++)
{
const unsigned char center = image_get_pixel_value(image_src, i, j , 0);
unsigned char code = 0;
if(center <= image_get_pixel_value(image_src, i-1, j-1 , 0))
code += 128;
if(center <= image_get_pixel_value(image_src, i-1, j , 0))
code += 64;
if(center <= image_get_pixel_value(image_src, i-1, j+1 , 0))
code += 32;
if(center <= image_get_pixel_value(image_src, i, j+1 , 0))
code += 16;
if(center <= image_get_pixel_value(image_src, i+1, j+1 , 0))
code += 8;
if(center <= image_get_pixel_value(image_src, i+1, j , 0))
code += 4;
if(center <= image_get_pixel_value(image_src, i+1, j-1 , 0))
code += 2;
if(center <= image_get_pixel_value(image_src, i, j-1 , 0))
code += 1;
image_set_pixel_value(image_tar, i-1, j-1, 0, code);
}
}
Run Code Online (Sandbox Code Playgroud)
这是查找表:
int UniformPattern59[16][16] = {
1, 2, 3, 4, 5, 0, 6, 7, 8, 0, 0, 0, 9, 0, 10, 11,
12, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 14, 0, 15, 16,
17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 20, 0, 21, 22,
23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 27, 0, 28, 29,
30, 31, 0, 32, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 34,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36,
37, 38, 0, 39, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 41,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42,
43, 44, 0, 45, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 47,
48, 49, 0, 50, 0, 0, 0, 51, 52, 53, 0, 54, 55, 56, 57, 58
};
Run Code Online (Sandbox Code Playgroud)
我想你可能会误解LBP的概念.LBP有几种变体:基本LBP,均匀LBP和旋转不变均匀LBP.
在基本LBP中,我们比较中心像素与其相邻像素之一的灰度值(内插像素以获得更准确的结果)以获得该比特的二进制编码(0或1).通常,我们将此编码方案的半径设置为1,将邻居数设置为8作为默认配置.因此,我们可以在比较所有8个邻居之后获得中心像素的局部二进制模式(LBP),这是8位二进制数,例如01011110或11110000.这里,我们可以看到这种类型的范围如果我们将二进制数转换为十进制数,则LBP从0到255.我们通常将每个像素的LBP代码分类为256种模式中的一种,以形成直方图,用于进一步分类或识别任务,即问题中的256个像素/像素.
然而,在均匀和旋转不变的均匀LBP中存在不同的东西.也就是说,图案的数量不是256,其中旋转不变的均匀LBP仅具有10种图案.旋转均匀LBP具有9个旋转均匀的LBP和1个其他LBP,其中9个旋转均匀的LBP通常覆盖图像上的90%图案.
因此,在旋转不变的均匀LBP中,您只需要生成10个柱的直方图以进行进一步处理,例如分类或识别.首先,将每个像素编码为旋转不变的均匀LBP,这可能会产生一个image.rows*image.cols矩阵.然后,将每个图案(矩阵元素)分类为10个图案中的一个以形成表示直方图的阵列.
一些文件供您参考: