1. 程式人生 > >Python + OpenCV 實現LBP特征提取

Python + OpenCV 實現LBP特征提取

ngs cal lar 顯示 a20 numpy .so naconda eat

背景

看了些許的紋理特征提取的paper,想自己實現其中部分算法,看看特征提取之後的效果是怎樣

運行環境

  • Mac OS
  • Python3.0
  • Anaconda3(集成了很多包,瀏覽器界面編程,清爽)

    步驟
    導入包
from skimage.transform import rotate
from skimage.feature import local_binary_pattern
from skimage import data, io,data_dir,filters, feature
from skimage.color import label2rgb
import skimage
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import cv2
參數設置
# settings for LBP
radius = 1  # LBP算法中範圍半徑的取值
n_points = 8 * radius # 領域像素點數
圖像讀取
# 讀取圖像
image = cv2.imread(‘img/logo.png‘)
#顯示到plt中,需要從BGR轉化到RGB,若是cv2.imshow(win_name, image),則不需要轉化
image1 = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.subplot(111)
plt.imshow(image1)

技術分享圖片

灰度轉換
image = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
plt.subplot(111)
plt.imshow(image, plt.cm.gray)
LBP處理
lbp = local_binary_pattern(image, n_points, radius)
plt.subplot(111)
plt.imshow(lbp, plt.cm.gray)

技術分享圖片

邊緣提取
edges = filters.sobel(image)
plt.subplot(111)
plt.imshow(edges, plt.cm.gray)

技術分享圖片

此致,敬禮

Python + OpenCV 實現LBP特征提取