我在 C 中实现统一的 LBP。但我对这个概念感到困惑。我已经实施了 LBP。假设我有一个 512*512 尺寸的图像。在 LBP 之后,它将是 510*510。现在如何从这个 LBP 图像中获得 256 个 bins/pixels。
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);
}
}
这是查找表:
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
};