Local Binary Pattern

Reference: T. Ojala, et al. "Performance evaluation of texture measures with classification based on Kullback discrimination of distributions", ICPR 1994, vol. 1, pp. 582 - 585.

Local Binary Pattern is a texture descriptor, introduced by Ojala et. al in 1994, based on the idea that a texture can be described by two measures: local spatial pattern and grayscale contrast. Each pixel on the image is labeled by thresholding the surrounding pixels with the value of the central pixel. Then, the resulting neighborhood is transformed into a binary number that is used as the label of the central pixel. TRIOSlib implementation of LBP uses the texture descriptor algorithm as a feature extractor.

The code below shows an example of learning an image operator from the CharS dataset using LBP as its feature extractor. Download the CharS dataset and modify the char_location variable to the directory where the dataset was extracted.

# file docs/examples/methods/lbp.py
from trios.classifiers import SKClassifier
from sklearn.tree import DecisionTreeClassifier
from trios.contrib.features.lbp import LBPExtractor
import trios
import numpy as np

import trios.shortcuts.persistence as p

chars_location = 'datasets/'
training = trios.Imageset.read(chars_location + 'characters/training.set')
testset = trios.Imageset.read(chars_location + 'characters/test.set')

if __name__ == "__main__":
    win = np.ones((9,9), np.uint8)
    op = trios.WOperator(win, SKClassifier(DecisionTreeClassifier()), LBPExtractor)
    print('Training')
    op.train(training)
    print('Evaluating')
    print('Accuracy:', 1 - op.eval(testset))
Accuracy: 0.9896342171863871