pub fn brief(
    image: &GrayImage,
    keypoints: &[Point<u32>],
    length: usize,
    override_test_pairs: Option<&Vec<TestPair>>,
) -> Result<(Vec<BriefDescriptor>, Vec<TestPair>), String> {
    // if we have test pairs already, use them; otherwise, generate some
    let test_pairs = if let Some(t) = override_test_pairs {
        t.clone()
    } else {
        // generate a set of test pairs within a 31x31 grid with a Gaussian bias (sigma = 6.6)
        let test_pair_distribution = Normal::new(BRIEF_PATCH_RADIUS as f32 + 1.0, 6.6).unwrap();
        let mut rng = rand::thread_rng();
        let mut test_pairs: Vec<TestPair> = Vec::with_capacity(length);
        while test_pairs.len() < length {
            let (x0, y0, x1, y1) = (
                test_pair_distribution.sample(&mut rng) as u32,
                test_pair_distribution.sample(&mut rng) as u32,
                test_pair_distribution.sample(&mut rng) as u32,
                test_pair_distribution.sample(&mut rng) as u32,
            );
            if x0 < BRIEF_PATCH_DIAMETER
                && y0 < BRIEF_PATCH_DIAMETER
                && x1 < BRIEF_PATCH_DIAMETER
                && y1 < BRIEF_PATCH_DIAMETER
            {
                test_pairs.push(TestPair {
                    p0: Point::new(x0, y0),
                    p1: Point::new(x1, y1),
                });
            }
        }
        test_pairs.clone()
    };

    let integral_image = integral_image(image);

    let descriptors = brief_impl(&integral_image, keypoints, &test_pairs, length)?;

    // return the descriptors for all the keypoints and the test pairs used
    Ok((descriptors, test_pairs))
}
Generates BRIEF descriptors for small patches around keypoints in an image.

Returns a tuple containing a vector of `BriefDescriptor` and a vector of
`TestPair`. All returned descriptors are based on the same `TestPair` set.
Patches are 31x31 pixels, so keypoints must be at least 17 pixels from any
edge. If any keypoints are too close to an edge, returns an error.

`length` must be a multiple of 128 bits. Returns an error otherwise.

If `override_test_pairs` is `Some`, then those test pairs are used, and none
are generated. Use this when you already have test pairs from another run
and want to compare the descriptors later.

If `override_test_pairs` is `None`, then `TestPair`s are generated according
to an isotropic Gaussian.

[Calonder, et. al. (2010)] used Gaussian smoothing to decrease the effects of noise in the
patches. This is slow, even with a box filter approximation. For maximum
performance, the average intensities of sub-patches of radius 5 around the
test points are computed and used instead of the intensities of the test
points themselves. This is much faster because the averages come from
integral images. Calonder suggests that this approach may be faster, and
[Rublee et. al. (2012)][rublee] use this approach to quickly compute ORB
descriptors.

[rublee]: http://www.gwylab.com/download/ORB_2012.pdf
[Calonder, et. al. (2010)]: https://www.cs.ubc.ca/~lowe/525/papers/calonder_eccv10.pdf
src/binary_descriptors/brief.rs