featuresLBP2.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyImageClassification 作者: tyiannak 项目源码 文件源码
def getLBP(img):
    img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    radius = 1
    n_points = 8 * radius
    lbpImage = (local_binary_pattern(img2, n_points, radius)).astype(int)**(1.0/radius)

    # block processing:
    lbpImages = block_view(lbpImage, ( int(lbpImage.shape[0] / 2), int(lbpImage.shape[1] / 4)))


    count = 0

    LBP = np.array([]); 
    for i in range(lbpImages.shape[0]):         # for each block:
        for j in range(lbpImages.shape[1]):
            count += 1
#           plt.subplot(4,2,count)
#           plt.imshow(lbpImages[i,j,:,:],cmap = cm.Greys_r)
#           plt.subplot(4,2,count+4*2/2)
#           print count*2+1
            LBPt = cv2.calcHist([lbpImages[i,j,:,:].astype('uint8')], [0], None, [8], [0, 256]) 
            LBP = np.append(LBP, LBPt[:,0]);
#           plt.plot(LBPt)
#   plt.show()


    Fnames = ["LBP"+str(i).zfill(2) for i in range(len(LBP))]

    return normalize(LBP).tolist(), Fnames
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号