# Local Binary Patterns¶

New in version 0.7: LBPs are available before, but an important bug was fixed in 0.7. It is highly recommended that you never use the older version.

Local binary patterns depend on the local region around each pixel. See the diagram below:

(Image reference: Wikipedia)

The reference pixel is in red, at the centre. A number of points are defined at a distance `r` from it. These are the green points. As you go from left to right, the number of green points increases.

The “pattern” in the name is the relationship of the value at the green points when compared to the central red point. We call it a binary pattern because all that is taken into account is whether the value at the green point is greater than the value at the red point.

As you can see, the green points do not necessarily fall exactly on another pixel, so we need to use interpolation to find a value for the green points.

## API Documentation¶

The `mahotas.features.lb` module contains the `lbp` function which implements LBPs.

`mahotas.features.lbp.``lbp`(image, radius, points, ignore_zeros=False)

Compute Linear Binary Patterns

The return value is a histogram of feature counts, where position `i` corresponds to the number of pixels that had code `i`. The codes are compressed so that impossible codes are not used. Therefore, this is the `i``th feature, not just the feature with binary code ``i`.

Parameters: image : ndarray input image (2-D numpy ndarray) radius : number (integer or floating point) radius (in pixels) points : integer nr of points to consider ignore_zeros : boolean, optional whether to ignore zeros (default: False) features : 1-D numpy ndarray histogram of features. See above for a caveat on the interpretation of these.
`mahotas.features.lbp.``lbp_transform`(image, radius, points, ignore_zeros=False, preserve_shape=True)

Compute Linear Binary Pattern Transform

The return value are the transformed pixel values histogram of feature counts, where position `i` corresponds to the number of pixels that had code `i`. The codes are compressed so that impossible codes are not used. Therefore, this is the `i``th feature, not just the feature with binary code ``i`.

Parameters: image : ndarray input image (2-D numpy ndarray) radius : number (integer or floating point) radius (in pixels) points : integer nr of points to consider ignore_zeros : boolean, optional whether to ignore zeros. Note that if you set this to `True`, you will need to set `preserve_shape` to False. (default: False) preserve_shape : boolean, optional whether to return an array with the same shape as `image`. (default: True) features : 1-D numpy ndarray histogram of features. See above for a caveat on the interpretation of these.

References

Gray Scale and Rotation Invariant Texture Classification with Local Binary Patterns
Ojala, T. Pietikainen, M. Maenpaa, T. Lecture Notes in Computer Science (Springer) 2000, ISSU 1842, pages 404-420