pub fn local_binary_pattern<I>(image: &I, x: u32, y: u32) -> Option<u8>
where
    I: GenericImage<Pixel = Luma<u8>>,
{
    let (width, height) = image.dimensions();
    if width == 0 || height == 0 {
        return None;
    }

    // TODO: It might be better to make this function private, and
    // TODO: require the caller to only provide valid x and y coordinates
    // TODO: the function may probably need to be unsafe then to leverage
    // TODO: on `unsafe_get_pixel`
    if x == 0 || x >= width - 1 || y == 0 || y >= height - 1 {
        return None;
    }

    // TODO: As with the fast corner detectors, this would be more efficient if
    // TODO: generated a list of pixel offsets once per image, and used those
    // TODO: offsets directly when reading pixels. To do this we'd need some traits
    // TODO: for images whose pixels are stored in contiguous rows/columns.
    let mut pattern = 0u8;

    // The sampled pixels have the following labels.
    //
    // 7  0  1
    // 6  p  2
    // 5  4  3
    //
    // The nth bit of a pattern is 1 if the pixel p
    // is strictly brighter than the neighbor in position n.
    let (center, neighbors) = unsafe {
        (
            image.unsafe_get_pixel(x, y)[0],
            [
                image.unsafe_get_pixel(x, y - 1)[0],
                image.unsafe_get_pixel(x + 1, y - 1)[0],
                image.unsafe_get_pixel(x + 1, y)[0],
                image.unsafe_get_pixel(x + 1, y + 1)[0],
                image.unsafe_get_pixel(x, y + 1)[0],
                image.unsafe_get_pixel(x - 1, y + 1)[0],
                image.unsafe_get_pixel(x - 1, y)[0],
                image.unsafe_get_pixel(x - 1, y - 1)[0],
            ],
        )
    };

    for i in 0..8 {
        pattern |= (1 & (neighbors[i] < center) as u8) << i;
    }

    Some(pattern)
}
Computes the basic local binary pattern of a pixel, or None
if it's too close to the image boundary.

The neighbors of a pixel p are enumerated in the following order:

<pre>
7  0  1
6  p  2
5  4  3
</pre>

The nth most significant bit of the local binary pattern at p is 1
if p is strictly brighter than the neighbor in position n.

# Examples
```
# extern crate image;
# #[macro_use]
# extern crate imageproc;
# fn main() {
use imageproc::local_binary_patterns::local_binary_pattern;

let image = gray_image!(
06, 11, 14;
09, 10, 10;
19, 00, 22);

let expected = 0b11010000;
let pattern = local_binary_pattern(&image, 1, 1).unwrap();
assert_eq!(pattern, expected);
# }
```
src/local_binary_patterns.rs