栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

快速提取图像LBP特征

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

快速提取图像LBP特征

快速提取图像LBP特征
      • Python代码

Python代码
def faster_LBP(img):
	'''输入一张灰度图'''
    dst = np.zeros(img.shape,dtype=img.dtype)
    # h, w = img.shape
    origin_array = cv2.merge([img for _ in range(8)])
    nei_array = np.zeros_like(origin_array)
    for i, (x_plus, y_plus) in enumerate(((-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1))):
        if y_plus - 1 == 0 and x_plus - 1 == 0:
            nei_array[1:-1, 1:-1, i] = img[y_plus + 1:, x_plus + 1:].copy()
        elif y_plus - 1 == 0:
            nei_array[1:-1, 1:-1, i] = img[y_plus + 1:, x_plus + 1:x_plus - 1].copy()
        elif x_plus - 1 == 0:
            nei_array[1:-1, 1:-1, i] = img[y_plus + 1:y_plus - 1, x_plus + 1:].copy()
        else:
            nei_array[1:-1, 1:-1, i] = img[y_plus + 1:y_plus - 1, x_plus + 1:x_plus - 1].copy()
    sub_array = nei_array.astype(np.int) - origin_array.astype(np.int)
    # sub_array = np.where(sub_array >= 0, 1, 0).astype(np.uint8)
    sub_array[sub_array >= 0] = 1
    sub_array[sub_array < 0] = 0
    sub_array = sub_array.astype(np.uint8)
    for i in range(8):
        dst += sub_array[:, :, i] * (2 ** (7 - i))
    dst[0, :] = 0
    dst[-1, :] = 0
    dst[:, 0] = 0
    dst[:, -1] = 0
    hist = cv2.calcHist([dst], [0], None, [256], [0, 255])
    return dst, hist   # 返回LBP特征图及灰度直方图
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/674882.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号