image-moments

Crates.ioimage-moments
lib.rsimage-moments
version0.5.0
sourcesrc
created_at2021-11-30 13:44:00.999602
updated_at2021-11-30 16:30:57.779433
descriptionEfficient and compile-time checked calculations of contour moments
homepagehttps://github.com/Christopher22/image-moments
repositoryhttps://github.com/Christopher22/image-moments
max_upload_size
id489789
size121,480
Christopher Gundler (Christopher22)

documentation

https://christopher22.github.io/image-moments/image_moments/index.html

README

image-moments

This crate provides efficient and compile-time checked calculations of contour moments. It strives to be as compatible to the corresponding OpenCV functions as possible while maintaining a "rusty" workflow. The computed order of moments is adjustable: You pay only for those moments that you require.

Usage

use image_moments::{Moments, Spatial};
use approx::assert_abs_diff_eq;

fn main() {
    // Points defining the contour
    let points = [
        (53, 19),
        (52, 20),
        (49, 20),
        // [...]
        (60, 25),
        (54, 19),
    ];

    // Calculate all spatial (aka "raw") contour moments up to the third order
    let moments: Spatial<f64, 3> = points.iter().collect();

    // Compare with those values generated by OpenCV
    assert_abs_diff_eq!(moments.get::<0, 0>(), 703.0);
    assert_abs_diff_eq!(moments.get::<1, 0>(), 52175.166666666664);
    assert_abs_diff_eq!(moments.get::<0, 1>(), 25661.5);
    assert_abs_diff_eq!(moments.get::<2, 0>(), 4084450.6666666665);
    assert_abs_diff_eq!(moments.get::<1, 1>(), 2024477.75);
    assert_abs_diff_eq!(moments.get::<0, 2>(), 1071256.0);
    assert_abs_diff_eq!(moments.get::<3, 0>(), 332589780.65000004);
    assert_abs_diff_eq!(moments.get::<2, 1>(), 166738807.83333334);
    assert_abs_diff_eq!(moments.get::<1, 2>(), 89124447.63333333);
    assert_abs_diff_eq!(moments.get::<0, 3>(), 50269189.75);

    // This will fail at compile time because it is not covered by the third order:
    // assert_abs_diff_eq!(moments.get::<0, 4>(), 50269189.75);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 28

cargo fmt