用于纹理分类的多块局部二值模式

此示例说明如何计算多块局部二进制模式(MB-LBP)特征以及如何将其可视化。

这些特征的计算类似于局部二进制模式(LBP),不同之处在于使用相加的块而不是单独的像素值。

MB-LBP是LBP的扩展,可以利用积分图像在多个尺度上进行恒定时间的计算。使用9个大小相等的矩形来计算特征。对于每个矩形,计算像素强度的总和。将这些和与中心矩形的和进行比较,确定了类似于LBP的特征(请参见 LBP )。

首先,我们生成一个图像来说明MB-LBP的功能:考虑一个(9,9)矩形并将其分成(3,3)块,然后对其应用MB-LBP。

from skimage.feature import multiblock_lbp
import numpy as np
from numpy.testing import assert_equal
from skimage.transform import integral_image

# Create test matrix where first and fifth rectangles starting
# from top left clockwise have greater value than the central one.
test_img = np.zeros((9, 9), dtype='uint8')
test_img[3:6, 3:6] = 1
test_img[:3, :3] = 50
test_img[6:, 6:] = 50

# First and fifth bits should be filled. This correct value will
#  be compared to the computed one.
correct_answer = 0b10001000

int_img = integral_image(test_img)

lbp_code = multiblock_lbp(int_img, 0, 0, 3, 3)

assert_equal(correct_answer, lbp_code)

现在,让我们将运算符应用于实际图像,看看可视化是如何工作的。

from skimage import data
from matplotlib import pyplot as plt
from skimage.feature import draw_multiblock_lbp

test_img = data.coins()

int_img = integral_image(test_img)

lbp_code = multiblock_lbp(int_img, 0, 0, 90, 90)

img = draw_multiblock_lbp(test_img, 0, 0, 90, 90,
                          lbp_code=lbp_code, alpha=0.5)


plt.imshow(img)

plt.show()
plot multiblock local binary pattern

在上图中,我们可以看到MB-LBP的计算结果和计算特征的可视化。亮度和小于中心矩形的矩形用青色标记。具有较高强度值的颜色标记为白色。中间的矩形保持不变。

脚本的总运行时间: (0分0.127秒)

Gallery generated by Sphinx-Gallery