pub fn filter<P, F, Q>(&self, image: &Image<P>, mut f: F) -> Image<Q>
    where
        P: Pixel + 'static,
        <P as Pixel>::Subpixel: ValueInto<K>,
        Q: Pixel + 'static,
        F: FnMut(&mut Q::Subpixel, K),
    {
        let (width, height) = image.dimensions();
        let mut out = Image::<Q>::new(width, height);
        let num_channels = P::CHANNEL_COUNT as usize;
        let zero = K::zero();
        let mut acc = vec![zero; num_channels];
        let (k_width, k_height) = (self.width as i64, self.height as i64);
        let (width, height) = (width as i64, height as i64);

        for y in 0..height {
            for x in 0..width {
                for k_y in 0..k_height {
                    let y_p = min(height - 1, max(0, y + k_y - k_height / 2)) as u32;
                    for k_x in 0..k_width {
                        let x_p = min(width - 1, max(0, x + k_x - k_width / 2)) as u32;
                        accumulate(
                            &mut acc,
                            unsafe { &image.unsafe_get_pixel(x_p, y_p) },
                            unsafe { *self.data.get_unchecked((k_y * k_width + k_x) as usize) },
                        );
                    }
                }
                let out_channels = out.get_pixel_mut(x as u32, y as u32).channels_mut();
                for (a, c) in acc.iter_mut().zip(out_channels.iter_mut()) {
                    f(c, *a);
                    *a = zero;
                }
            }
        }

        out
    }
/// Returns 2d correlation of an image. Intermediate calculations are performed
/// at type K, and the results converted to pixel Q via f. Pads by continuity.
Returns 2d correlation of an image. Intermediate calculations are performed
at type K, and the results converted to pixel Q via f. Pads by continuity.
Returns 2d correlation of an image . Intermediate calculations are performed at type K and the results converted to pixel Q via f . Pads by continuity .
pub fn filter<P, F, Q>(&self, image: &Image<P>, mut f: F) -> Image<Q>
    where
        P: Pixel + 'static,
        <P as Pixel>::Subpixel: ValueInto<K>,
        Q: Pixel + 'static,
        F: FnMut(&mut Q::Subpixel, K),
    {
        let (width, height) = image.dimensions();
        let mut out = Image::<Q>::new(width, height);
        let num_channels = P::CHANNEL_COUNT as usize;
        let zero = K::zero();
        let mut acc = vec![zero; num_channels];
        let (k_width, k_height) = (self.width as i64, self.height as i64);
        let (width, height) = (width as i64, height as i64);
        for y in 0..height {
            for x in 0..width {
                for k_y in 0..k_height {
                    let y_p = min(height - 1, max(0, y + k_y - k_height / 2)) as u32;
                    for k_x in 0..k_width {
                        let x_p = min(width - 1, max(0, x + k_x - k_width / 2)) as u32;
                        accumulate(
                            &mut acc,
                            unsafe { &image.unsafe_get_pixel(x_p, y_p) },
                            unsafe { *self.data.get_unchecked((k_y * k_width + k_x) as usize) },
                        );
                    }
                }
                let out_channels = out.get_pixel_mut(x as u32, y as u32).channels_mut();
                for (a, c) in acc.iter_mut().zip(out_channels.iter_mut()) {
                    f(c, *a);
                    *a = zero;
                }
            }
        }
        out
    }
pub fn filter < P , F , Q > ( & self , image : & Image < P > , mut f : F ) -> Image < Q > where P : Pixel + ' static , < P as Pixel > :: Subpixel : ValueInto < K > , Q : Pixel + ' static , F : FnMut ( & mut Q :: Subpixel , K ) , { let ( width , height ) = image . dimensions ( ) ; let mut out = Image :: < Q > :: new ( width , height ) ; let num_channels = P :: CHANNEL_COUNT as usize ; let zero = K :: zero ( ) ; let mut acc = vec ! [ zero num_channels ] ; let ( k_width , k_height ) = ( self . width as i64 , self . height as i64 ) ; let ( width , height ) = ( width as i64 , height as i64 ) ; for y in 0 .. height { for x in 0 .. width { for k_y in 0 .. k_height { let y_p = min ( height - 1 , max ( 0 , y + k_y - k_height / 2 ) ) as u32 ; for k_x in 0 .. k_width { let x_p = min ( width - 1 , max ( 0 , x + k_x - k_width / 2 ) ) as u32 ; accumulate ( & mut acc , unsafe { & image . unsafe_get_pixel ( x_p , y_p ) } , unsafe { * self . data . get_unchecked ( ( k_y * k_width + k_x ) as usize ) } , ) ; } } let out_channels = out . get_pixel_mut ( x as u32 , y as u32 ) . channels_mut ( ) ; for ( a , c ) in acc . iter_mut ( ) . zip ( out_channels . iter_mut ( ) ) { f ( c , * a ) ; * a = zero ; } } } out }
Returns 2d correlation of an image.
Returns 2d correlation of an image .
&self
image
&Image<P>
f
F
&self
image
&Image<P>
f
F