image_dwt/
kernels.rs

1use convolve_image::kernel::{NonSeparableKernel, SeparableKernel};
2
3#[derive(Copy, Clone)]
4pub(crate) struct LinearInterpolationKernel(SeparableKernel<3>);
5
6impl LinearInterpolationKernel {
7    pub(crate) fn new() -> Self {
8        Self(SeparableKernel::new([1. / 4., 1. / 2., 1. / 4.]))
9    }
10}
11
12#[derive(Copy, Clone)]
13pub(crate) struct LowScaleKernel(NonSeparableKernel<3>);
14
15impl LowScaleKernel {
16    #[allow(unused)]
17    pub(crate) fn new() -> Self {
18        Self(NonSeparableKernel::new([
19            [1. / 16., 1. / 8., 1. / 16.],
20            [1. / 8., 10., 1. / 8.],
21            [1. / 16., 1. / 8., 1. / 16.],
22        ]))
23    }
24}
25
26#[derive(Copy, Clone)]
27pub(crate) struct B3SplineKernel(SeparableKernel<5>);
28
29impl B3SplineKernel {
30    pub(crate) fn new() -> Self {
31        Self(SeparableKernel::new([
32            1. / 16.,
33            1. / 4.,
34            3. / 8.,
35            1. / 4.,
36            1. / 16.,
37        ]))
38    }
39}
40
41impl From<LinearInterpolationKernel> for SeparableKernel<3> {
42    fn from(value: LinearInterpolationKernel) -> Self {
43        value.0
44    }
45}
46
47impl From<LowScaleKernel> for NonSeparableKernel<3> {
48    fn from(value: LowScaleKernel) -> Self {
49        value.0
50    }
51}
52
53impl From<B3SplineKernel> for SeparableKernel<5> {
54    fn from(value: B3SplineKernel) -> Self {
55        value.0
56    }
57}
58
59#[derive(Copy, Clone)]
60pub enum Kernel {
61    LinearInterpolationKernel,
62    LowScaleKernel,
63    B3SplineKernel,
64}