使用lbp方法提取图片特征(python写)

自己根据前人的代码,使用lbp算子提取图片特征,并对其中的部分参数进行了注释。

下面是我的代码示例:

# coding: utf-8
import cv2 as cv
from skimage import feature as skif
import numpy as np

#获取图像的lbp特征
def get_lbp_data(image_path, lbp_radius=1, lbp_point=8):
    # img = utils.change_image_rgb(image_path)
    img = cv.imread(image_path)
    image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    # 使用LBP方法提取图像的纹理特征.
    #lbp_point:选取中心像素周围的像素点的个数;lbp_radius:选取的区域的半径
    #以下为5种不同的方法提取的lbp特征,相应的提取到的特征维度也不一样
    #'default': original local binary pattern which is gray scale but notrotation invariant
    #'ror': extension of default implementation which is gray scale androtation invariant
    #'uniform': improved rotation invariance with uniform patterns andfiner quantization of the angular space which is gray scale and rotation invariant.
    #'nri_uniform': non rotation-invariant uniform patterns variantwhich is only gray scale invariant
    #'var': rotation invariant variance measures of the contrast of localimage texture which is rotation but not gray scale invariant
    lbp = skif.local_binary_pattern(image, lbp_point, lbp_radius, 'default')
    # 统计图像的直方图
    max_bins = int(lbp.max() + 1)
    #print(max_bins)
    # hist size:256
    hist, _ = np.histogram(lbp, density=True, bins=max_bins, range=(0, max_bins))
    return hist

image_path = 'airplane009.jpg'  #读取图片
feature = get_lbp_data(image_path)  #调用函数
print(feature)

下面是我的部分结果输出:
使用lbp方法提取图片特征(python写)_第1张图片

你可能感兴趣的:(使用lbp方法提取图片特征(python写))