atranitell
7/1/2017 - 5:53 AM

[cv] handcraft feature #cv #python

[cv] handcraft feature #cv #python

import numpy as np
import skimage.feature
import skimage.filters
from PIL import Image


def array_to_image(x):
    return Image.fromarray(np.uint8(x))


def image_to_array(x):
    return np.array(x, dtype=np.float)


def LBP(img):
    img = array_to_image(img).convert('L')
    img = img.resize((64, 64))
    lbp = skimage.feature.local_binary_pattern(img, 8, 4)
    return lbp


def read_image(imgpath):
    img = Image.open(imgpath)
    img_grey = img.convert('L')
    return img, img_grey