#wavelet #dwt #computer-vision

omni-wave

Easy to use DWT (Discrete Wavelet Transform) library, no need to worry about padding, and a variety of wavelets are available

2 unstable releases

0.2.1 Jun 2, 2023
0.1.0 May 30, 2023

#762 in Math

22 downloads per month

MIT/Apache

40KB
579 lines

omni-wave

Easy to use DWT (Discrete Wavelet Transform) library, no need to worry about padding, and a variety of wavelets are available.

CAUTION: My knowledge can't vouch for it being "correct", but it does "concentrate energy" and "reconstruct perfectly".

use approx::assert_abs_diff_eq;
use ndarray::{Array1, Array2, Axis};
use omni_wave::*;

let wavelet = wavelet::BIOR_3_1;
let love = Array2::from_shape_vec((8, 8),
vec![0., 0., 0., 0., 0., 0., 0., 0.,
     0., 0.,99., 0., 0.,99., 0., 0.,
     0.,99.,99.,99.,99.,99.,99., 0.,
     0.,99.,99.,99.,99.,99.,99., 0.,
     0.,99.,99.,99.,99.,99.,99., 0.,
     0., 0.,99.,99.,99.,99., 0., 0.,
     0., 0., 0.,99.,99., 0., 0., 0.,
     0., 0., 0., 0., 0., 0., 0., 0.,]).unwrap();

let mut signal = love.clone();
let mut buffer = Array1::zeros(signal.len_of(Axis(0)) + wavelet.window_size() - 2); // The minimum length of a buffer

completely_decompose_2d(signal.view_mut(), buffer.view_mut(), wavelet);
completely_reconstruct_2d(signal.view_mut(), buffer.view_mut(), wavelet);

love.into_iter()
    .zip(signal)
    .for_each(|(a, b)| assert_abs_diff_eq!(a, b, epsilon = 0.0001));

Features

  • f64 - The default primitive type used for calculations is f32. Enable this feature to switch to f64.

Knowledges

Signal

The data need to transform. The length should be even. Failure to meet the length requirement may not result a panic, but the behavior of functions will be undefined.

The left half of the input will be considered as Approx, while the right half will be considered as Detail.

Padding

The extension of a signal when processing. Our filling method named periodic (in PyWavelets), ppd (in Matlab) or wrap (in numpy.pad).

[ A.B.C.D.E.F.G.H ] a.b.c.d ...
  ↑^^^^^^^^^^^^^^   ↑^^^^^^
  Original signal   Padding: automatically fill & detach.

Originally, I planned to provide more extension mode, but found that the first coefficient of wavelets such as bior2.2 is zero... Wouldn't the information be lost in this way? ? So currently only periodic mode is provided. Let me know if you have a better suggestion.

Buffer

Temporary buffer for calculations. For performance, it is strongly recommended that it be contiguous in memory.

window_size

The number of wavelet coefficients.

Dependencies

~1.5MB
~25K SLoC