/// Calculates sum of absolute pixel differences between images.
Calculates sum of absolute pixel differences between images.
Calculates sum of absolute pixel differences between images .
fn calc_sum_of_abs_diffs(img1: &ImageView, img2: &ImageView) -> u64 {
    assert!(img1.pixel_format() == PixelFormat::Mono8);
    assert!(img2.pixel_format() == PixelFormat::Mono8);
    assert!(img1.width() == img2.width());
    assert!(img1.height() == img2.height());
    let mut sum_diffs = 0u64;
    for y in 0..img1.height() {
        let line1 = img1.line_raw(y);
        let line2 = img2.line_raw(y);
        //TODO: use unsafe access
        sum_diffs += (0..img1.width()).fold(0, |sum, i| {
            sum + (line1[i as usize] as i16 - line2[i as usize] as i16).pow(2) as u64
        });
    }
    sum_diffs
}
fn calc_sum_of_abs_diffs ( img1 : & ImageView , img2 : & ImageView ) -> u64 { assert ! ( img1 pixel_format ( ) PixelFormat Mono8 ) ; assert ! ( img2 pixel_format ( ) PixelFormat Mono8 ) ; assert ! ( img1 width ( ) img2 width ( ) ) ; assert ! ( img1 height ( ) img2 height ( ) ) ; let mut sum_diffs = 0u64 ; for y in 0 .. img1 . height ( ) { let line1 = img1 . line_raw ( y ) ; let line2 = img2 . line_raw ( y ) ; //TODO: use unsafe access sum_diffs += ( 0 .. img1 . width ( ) ) . fold ( 0 , | sum , i | { sum + ( line1 [ i as usize ] as i16 - line2 [ i as usize ] as i16 ) . pow ( 2 ) as u64 } ) ; } sum_diffs }
Calculates sum of absolute pixel differences between images.
Calculates sum of absolute pixel differences between images .
img1
&ImageView
img2
&ImageView