In this example, we will see how to classify textures based on LBP (Local
Binary Pattern). LBP looks at points surrounding a central point and tests
whether the surrounding points are greater than or less than the central point
(i.e. gives a binary result).
Before trying out LBP on an image, it helps to look at a schematic of LBPs.
The below code is just used to plot the schematic.
The figure above shows example results with black (or white) representing
pixels that are less (or more) intense than the central pixel. When
surrounding pixels are all black or all white, then that image region is
flat (i.e. featureless). Groups of continuous black or white pixels are
considered “uniform” patterns that can be interpreted as corners or edges.
If pixels switch back-and-forth between black and white pixels, the pattern
is considered “non-uniform”.
When using LBP to detect texture, you measure a collection of LBPs over an
image patch and look at the distribution of these LBPs. Lets apply LBP to a
brick texture.
The above plot highlights flat, edge-like, and corner-like regions of the
image.
The histogram of the LBP result is a good measure to classify textures.
Here, we test the histogram distributions against each other using the
Kullback-Leibler-Divergence.
Rotated images matched against references using LBP:
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/skimage/feature/texture.py:385: UserWarning:
Applying `local_binary_pattern` to floating-point images may give unexpected results when small numerical differences between adjacent pixels are present. It is recommended to use this function with images of integer dtype.
original: brick, rotated: 30deg, match result: brick
original: brick, rotated: 70deg, match result: brick
original: grass, rotated: 145deg, match result: grass
Total running time of the script: (0 minutes 1.751 seconds)