# Basis of wavelet transform

### Wavelet basis

The principle understanding and why wavelet should be used can be referred to as follows: https://zhuanlan.zhihu.com/p/22450818 , some of which are helpful for understanding wavelet transform. The basic contents are as follows:

1. Fourier transform (FT) can better analyze the frequency information of signal, but because ft must analyze a signal (lasting for a period of time) to get a more accurate frequency result, FT can only get the frequency distribution of non-stationary signal (the frequency of signal will change constantly), but can not give the time of specific frequency component Between. This results in very different signals (frequency rise and fall) in time and frequency, and FT will get the same result.

2. In order to improve the time insensitivity of FT, a short-time Fourier transform (STFT) is proposed, which is to divide the signal into several segments with windows to improve the time dimension analysis results. But it involves the choice of window size. If the window is large, the accuracy of time analysis will decrease; if the window is small, the accuracy of frequency analysis will decrease.

3. Wavelet transform transforms the infinite trigonometric function base into the finite attenuation wavelet base, and increases the scale (frequency) and offset (time) dimensions to realize the analysis of signal time and frequency dimensions.

### Image 2D DWT

Its essence is to carry out one-dimensional discrete wavelet transform on the row first, then one-dimensional wavelet transform on the column to get LL which contains the low-frequency part of the image, HL which contains the high-frequency in the horizontal direction and the low-frequency in the vertical direction (longitudinal boundary), LH which contains the low-frequency in the horizontal direction and the high-frequency in the vertical direction (transverse boundary), HH which contains the horizontal and the vertical direction High frequency (diagonal boundary).

The specific implementation method can be simplified to take the mean value and the difference in the horizontal and vertical directions respectively.

/************************************************* Copyright:zhuchen Author: zhuchen Date:2016-01-10 Description:Multilevel haar wavelet transform **************************************************/ # include<opencv2/opencv.hpp> # include<iostream> using namespace std; using namespace cv; int main() { Mat img = imread("lenna.bmp", 0); int Height = img.cols; int Width = img.rows; int depth = 3; //Define decomposition depth int depthcount = 1; Mat tmp = Mat::ones(Width, Height, CV_32FC1); Mat wavelet = Mat::ones(Width, Height, CV_32FC1); Mat imgtmp = img.clone(); imgtmp.convertTo(imgtmp, CV_32FC1); while (depthcount <= depth) { Width = img.rows / depthcount; Height = img.cols / depthcount; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height / 2; j++) { tmp.at<float>(i, j) = (imgtmp.at<float>(i, 2 * j) + imgtmp.at<float>(i, 2 * j + 1)) / 2; tmp.at<float>(i, j + Height / 2) = (imgtmp.at<float>(i, 2 * j) - imgtmp.at<float>(i, 2 * j + 1)) / 2; } } for (int i = 0; i < Width / 2; i++) { for (int j = 0; j < Height; j++) { wavelet.at<float>(i, j) = (tmp.at<float>(2 * i, j) + tmp.at<float>(2 * i + 1, j)) / 2; wavelet.at<float>(i + Width / 2, j) = (tmp.at<float>(2 * i, j) - tmp.at<float>(2 * i + 1, j)) / 2; } } imgtmp = wavelet; depthcount++; } namedWindow("jpg", 0); wavelet.convertTo(wavelet, CV_8UC1); wavelet += 50; //The image is too dark, so here I add 50 imshow("jpg", wavelet); waitKey(0); return 0; }