Quick Start
Build & Install
WaveletCV is built and installed using cmake 3.24 or newer.
# Download
git clone https://github.com/cindolfi/waveletcv.git
cd waveletcv
git checkout v0.1.0
# Configure
mkdir build
cmake -B build -DCMAKE_BUILD_TYPE=Release
# Build
cmake ---build build
# Install To /usr/local
sudo cmake --install build
Basic Usage
Wavelet Objects
#include <wtcv/wavelet.hpp>
Builtin wavelets are created by name
wtcv::Wavelet wavelet = wtcv::Wavelet::create("db2");
or by factory
wtcv::Wavelet wavelet = wtcv::create_daubuchies(2);
Accessing the filter banks decomposition and reconstruction kernels
wavelet.filter_bank().decompose_kernels().lowpass()
wavelet.filter_bank().decompose_kernels().highpass()
wavelet.filter_bank().reconstruct_kernels().lowpass()
wavelet.filter_bank().reconstruct_kernels().highpass()
See also
Discrete Wavelet Transform (DWT)
#include <wtcv/dwt2d.hpp>
Performing a discrete wavelet transformation (DWT) of an image is done using a functional style
cv::Mat image = cv::imread(filename);
DWT2D::Coeffs coeffs = wtcv::dwt2d(image, "db2");
or an object oriented approach
wtcv::Wavelet wavelet = wtcv::Wavelet::create("db2");
int levels = 2;
wtcv::DWT2D dwt(wavelet);
wtcv::DWT2D::Coeffs coeffs = dwt(image, levels);
Reconstruct the image by inverting the DWT
cv::Mat reconstructed_image = coeffs.reconstruct();
Accessing DWT Coefficients
Note
The horizontal detail coefficients are used for illustration. There are corresponding accessors for vertical and diagonal detail coefficients.
Access the approximation coefficients
cv::Mat approx_coeffs = coeffs.approx();
Access the finest scale (i.e. highest resolution) horizontal subband coefficients
cv::Mat finest_horizontal_coeffs = coeffs.horizontal_detail(0);
coeffs.set_horizontal_detail(0, finest_horizontal_coeffs);
Or use the parameterized subband version
cv::Mat finest_horizontal_coeffs = coeffs.detail(wtcv::HORIZONTAL, 0);
coeffs.set_detail(0, wtcv::HORIZONTAL, finest_horizontal_coeffs);
Negative Level Indexing
Use negative level indexing to access the coarsest scale (i.e. lowest resolution) horizontal subband coefficients
// Equivalent to coeffs.horizontal_detail(coeffs.levels() - 1)
cv::Mat coarsest_horizontal_coeffs = coeffs.horizontal_detail(-1);
coeffs.set_horizontal_detail(-1, coarsest_horizontal_coeffs);
Collect Details At Multiple Scales
Get horizontal detail coefficients at every scale
std::vector<cv::Mat> horizontal_details = coeffs.collect_horizontal_details();
Get detail coefficients at every scale and subband
std::vector<wtcv::DWT2D::Coeffs::DetailTuple>> details = coeffs.details();
See also
wtcv-dwt2d for a complete example
Shrink DWT Coefficients
#include <wtcv/shrink.hpp>
wtcv::DWT2D::Coeffs coeffs = ...;
Shrinking DWT coefficients is the basis for many denoising and compression applications. There are several shrinking algorithms implemented. Take the BayesShrink algorithm as an example
coeffs = wtcv::bayes_shrink(coeffs);
Alternatively, the object oriented API can be used in a polymorphic way
wtcv::Shrinker* shrinker = new wtcv::BayesShrinker();
coeffs = shrinker->shrink(coeffs);
or as a function object
wtcv::BayesShrinker shrink;
coeffs = shrink(coeffs);
The functional API is simpler and more succinct, whereas the object oriented API offers more options to fine tune the algorithm.
See also
wtcv-denoise for a complete example