1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::evolution::EvolutionStep;
use crate::image::GrayFloatImage;
use crate::{derivatives, Akaze};
use ndarray::azip;

impl Akaze {
    fn compute_multiscale_derivatives(&self, evolutions: &mut Vec<EvolutionStep>) {
        for evolution in evolutions.iter_mut() {
            // The image decreases in size by a factor which is 2^octave.
            let ratio = 2.0f64.powi(evolution.octave as i32);
            // The scale of the edge filter.
            let sigma_size = f64::round(evolution.esigma * self.derivative_factor / ratio) as u32;
            compute_multiscale_derivatives_for_evolution(evolution, sigma_size);
        }
    }

    /// Compute the detector response - the determinant of the Hessian - and save the result
    /// in the evolutions.
    ///
    /// # Arguments
    /// * `evolutions` - The computed evolutions.
    /// * `options` - The options
    #[allow(non_snake_case)]
    pub fn detector_response(&self, evolutions: &mut Vec<EvolutionStep>) {
        self.compute_multiscale_derivatives(evolutions);
        for evolution in evolutions.iter_mut() {
            let ratio = f64::powi(2.0, evolution.octave as i32);
            let sigma_size = f64::round(evolution.esigma * self.derivative_factor / ratio);
            let sigma_size_quat = sigma_size.powi(4) as f32;
            evolution.Ldet = GrayFloatImage::new(evolution.Lxx.width(), evolution.Lxx.height());
            azip!((
                Ldet in evolution.Ldet.mut_array2(),
                &Lxx in evolution.Lxx.ref_array2(),
                &Lyy in evolution.Lyy.ref_array2(),
                &Lxy in evolution.Lxy.ref_array2(),
            ) {
                *Ldet = ((Lxx * Lyy) - (Lxy * Lxy)) * sigma_size_quat;
            });
        }
    }
}

fn compute_multiscale_derivatives_for_evolution(evolution: &mut EvolutionStep, sigma_size: u32) {
    evolution.Lx = derivatives::scharr_horizontal(&evolution.Lsmooth, sigma_size);
    evolution.Ly = derivatives::scharr_vertical(&evolution.Lsmooth, sigma_size);
    evolution.Lxx = derivatives::scharr_horizontal(&evolution.Lx, sigma_size);
    evolution.Lyy = derivatives::scharr_vertical(&evolution.Ly, sigma_size);
    evolution.Lxy = derivatives::scharr_vertical(&evolution.Lx, sigma_size);
}