Skip to main content

burn_nn/modules/interpolate/
mod.rs

1mod interpolate1d;
2mod interpolate2d;
3
4pub use interpolate1d::*;
5pub use interpolate2d::*;
6
7use burn_core as burn;
8
9use burn::config::Config;
10use burn::tensor::ops::InterpolateMode as OpsInterpolateMode;
11
12/// Algorithm used for downsampling and upsampling
13///
14/// This enum defines different interpolation modes for resampling data.
15#[derive(Config, Debug)]
16pub enum InterpolateMode {
17    /// Nearest-neighbor interpolation
18    ///
19    /// This mode selects the value of the nearest sample point for each output pixel.
20    /// It is applicable for both temporal and spatial data.
21    Nearest,
22
23    /// Linear interpolation
24    ///
25    /// This mode calculates the output value using linear
26    /// interpolation between nearby sample points.
27    ///
28    /// It is applicable for both temporal and spatial data.
29    Linear,
30
31    /// Cubic interpolation
32    ///
33    /// This mode uses cubic interpolation to calculate the output value
34    /// based on surrounding sample points.
35    ///
36    /// It is applicable for both temporal and spatial data and generally
37    /// provides smoother results than linear interpolation.
38    Cubic,
39
40    /// Lanczos3 interpolation
41    ///
42    /// This mode uses a 6-tap sinc-based Lanczos filter (a=3) to calculate
43    /// the output value. It generally provides high-quality results,
44    /// especially for downsampling.
45    Lanczos,
46}
47
48impl From<InterpolateMode> for OpsInterpolateMode {
49    fn from(mode: InterpolateMode) -> Self {
50        match mode {
51            InterpolateMode::Nearest => OpsInterpolateMode::Nearest,
52            InterpolateMode::Linear => OpsInterpolateMode::Bilinear,
53            InterpolateMode::Cubic => OpsInterpolateMode::Bicubic,
54            InterpolateMode::Lanczos => OpsInterpolateMode::Lanczos3,
55        }
56    }
57}