14 KiB
List of Functions for wavelet2d Library
1D DWT/IDWT Functions
Both periodic and symmetric extension methods for Decimated DWT take exactly same input arguments.The difference is that Output vector in periodic extension has usually the same size (~N) as the input vector(N) while output vector in symmetric extension case has redundancies with length depending on size of filter used.
Periodic Extension
1. DWT: void* dwt(vector<double> &sig, int J, string nm, vector<double> &dwt_output,vector<double> &flag, vector<int> &length )
where,
sig :: Input Signal vector
J :: Decomposition levels
nm :: Wavelet Name (See filtcoef for available wavelet families)
length :: Lengths of respective approximation and detail vectors are stored in this integer vector.
dwt_output :: Output of Discrete Wavelet Transform. It stores coefficients in following format:
[A(J) D(J) D(J-1) ..... D(1)]
where A(J) is the approximation coefficient vector at the Jth level while D(n) are the detail coefficient vectors at the nth level.lengthcontains the lengths of corresponding vectors. Last entry of thelengthvector is the length of the original signal.
flag :: Housekeeping vector. In this implementation it contains two values-
flag0 is 0 if the signal is even and it is 1 if signal is odd and if it is made even by repeating the last value one more time
flag1 - contains the decomposition levels.
Housekeeping vector is a double vector as it was originally meant to store more values than it currently does
DWT stats (periodic extension) for an input signal of length 256
2. IDWT: void* idwt(vector<double> &dwtop,vector<double> &flag, string nm,vector<double> &idwt_output,vector<int> &length)
where,
dwtop :: is the DWT vector
flag :: Same Housekeeping function as obtained from the DWT function
nm :: Wavelet Used
idwt_output :: Output of IDWT
length :: Length vector obtained from the DWT computations
Symmetric Extension
3. DWT: void* dwt_sym(vector<double> &sig, int J, string nm, vector<double> &dwt_output,vector<double> &flag, vector<int> &length )
where,
sig :: Input Signal vector
J :: Decomposition levels
nm :: Wavelet Name (See filtcoef for available wavelet families)
length :: Lengths of respective approximation and detail vectors are stored in this integer vector.
dwt_output :: Output of Discrete Wavelet Transform. It stores coefficients in following format:
[A(J) D(J) D(J-1) ..... D(1)]
where A(J) is the approximation coefficient vector at the Jth level while D(n) are the detail coefficient vectors at the nth level.lengthcontains the lengths of corresponding vectors. Last entry of thelengthvector is the length of the original signal.
flag :: Housekeeping vector. In this implementation it contains two values-
flag0 is 0 if the signal is even and it is 1 if signal is odd and if it is made even by repeating the last value one more time
flag1 - contains the decomposition levels.
Housekeeping vector is a double vector as it was originally meant to store more values than it currently does
idwt_output :: Output of the Inverse Discrete Wavelet Transform
length :: Length Vector Obtained from the DWT computations
DWT stats (symmetric extension) for an input signal of length 256
4. IDWT: void* idwt_sym(vector<double> &dwtop,vector<double> &flag, string nm,vector<double> &idwt_output,vector<int> &length)
where,
dwtop :: is the DWT vector
flag :: Same Housekeeping function as obtained from the DWT function
nm :: Wavelet Used
idwt_output :: Output of IDWT
length :: Length vector obtained from the DWT computations
1D SWT/ISWT Functions
5. SWT: void* swt(vector<double> &sig, int J, string nm, vector<double> &swt_output, int &length)
All the coefficients are of equal lengths and that value is stored in length. swt_output stores value in the same format as dwt and dwt_sym functions - Approximation coefficient vector at level J is stored at the beginning of the swt_output vector followed by detail coefficients vectors at levels J, J-1,...., 1. The signal length has to be divisible by 2^J for reliable results. You can use signal extension (see below) to make the lengths compatible with the SWT.
Two Level SWT Decomposition of a 247 length signal vector
6. ISWT: void* iswt(vector<double> &swtop,int J, string nm, vector<double> &iswt_output)
swtop is the output of SWT stage , J - number of levels and nm is the wavelet as before. Output of ISWT is stored in iswt_output vector.
2D DWT/IDWT Functions
As in 1D case, both periodic and symmetric extension methods for Decimated DWT take exactly same input arguments.The difference is that Output vector in periodic extension has usually the same size (~NXN) as the input vector(NXN) while output vector in symmetric extension case has redundancies with length/breadth depending on size of filter used.
Periodic Extension
7. 2D DWT: void* dwt_2d(vector<vector<double> > &origsig, int J, string nm, vector<double> &dwt_output,vector<double> &flag, vector<int> &length)
origsig :: Input Image/Matrix
J :: Number of Decomposition Levels
nm :: Wavelet Name
flag :: Stores values for IDWT function.Only flag0 value is important as it contains decomposition levels.
dwt_output :: 1D vector that stores the output in the following format A(J) Dh(J) Dv(J) Dd(J) ..... Dh(1) Dv(1) Dd(1)
where A(J) is the approximation coefficient vector at the Jth level while D(n) are the three detail coefficient vectors(horizontal,vertical and detail) at the nth level. It is important to remember that approximation and detail coefficients are actually two dimensional so we need a length vector that stores rows and columns values of each coefficient element. The length vector is given by length.
For example, the first element of output vector is the approximation matrix stored as a vector and the first two elements of length vectors are row and column values of the approximation matrix. In other words, a 300 element approximation matrix ( 15 rows X 20 columns) can be extracted from the 300 element approximation vector.
2D DWT computation using periodic extension
8. 2D IDWT: void* idwt_2d(vector<double> &dwtop,vector<double> &flag, string nm,vector<vector<double> > &idwt_output, vector<int> &length)
where,
dwtop :: is the DWT vector
flag :: Same Housekeeping function as obtained from the DWT function
nm :: Wavelet Used
idwt_output :: Output of IDWT which should be defined to have the same number of rows and columns as the input image/matrix
length :: Length vector obtained from the DWT computations
Symmetric Extension
9. 2D DWT: void* dwt_2d_sym(vector<vector<double> > &origsig, int J, string nm, vector<double> &dwt_output,vector<double> &flag, vector<int> &length)
origsig :: Input Image/Matrix
J :: Number of Decomposition Levels
nm :: Wavelet Name
flag :: Stores values for IDWT function.Only flag0 value is important as it contains decomposition levels.
dwt_output :: 1D vector that stores the output in the following format A(J) Dh(J) Dv(J) Dd(J) ..... Dh(1) Dv(1) Dd(1)
where A(J) is the approximation coefficient vector at the Jth level while D(n) are the three detail coefficient vectors(horizontal,vertical and detail) at the nth level. It is important to remember that approximation and detail coefficients are actually two dimensional so we need a length vector that stores rows and columns values of each coefficient element. The length vector is given by length.
For example, the first element of output vector is the approximation matrix stored as a vector and the first two elements of length vectors are row and column values of the approximation matrix. In other words, a 300 element approximation matrix ( 15 rows X 20 columns) can be extracted from the 300 element approximation vector.
2D DWT computation using symmetric extension
10. 2D IDWT: void* idwt_2d_sym(vector<double> &dwtop,vector<double> &flag, string nm,vector<vector<double> > &idwt_output, vector<int> &length)
where,
dwtop :: is the DWT vector
flag :: Same Housekeeping function as obtained from the DWT function
nm :: Wavelet Used
idwt_output :: Output of IDWT which should be defined to have the same number of rows and columns as the input image/matrix
length :: Length vector obtained from the DWT computations
2D SWT Function
11. 2D SWT: void* swt_2d(vector<vector<double> > &sig,int J, string nm, vector<double> &swt_output)
swt_output is a 1D vector which is arranged the same way as DWT output vector in the Decimated 2D cases above except that in this case all coefficients are of same size. This is a highly redundant transform as a three level decomposition of a 512X512 image results in 10 512X512 images - one approximation image and 9 detail images (three at each level).
Convolution
12. Convolution FFT_ESTIMATE (Recommended): double convfft(vector<double> &a, vector<double> &b, vector<double> &c)
Convolution function is pretty straightforward. a and b are input vectors and c is the convolution output. convfft uses FFT so it gives better results in most cases than the regular convolution which is implemented by convol function.
13. Convolution Direct (Use it for only smaller vectors): double convol(vector<double> &a, vector<double> &b, vector<double> &c)
14. Convolution FFT_MEASURE (Recommended if you are going to perform convolutions of same length hundreds or thousands of time in one program): double convfftm(vector<double> &a, vector<double> &b, vector<double> &c)
convfftm is performed using MEASUREing capabilities of FFTW3 library so it is not recommended if you are going to convolve two vectors only once. This has some overhead but gives good results if multiple instances of same convolution are performed repeatedly.
Wavelet Filters
15. Filters: int filtcoef(string nm, vector<double> &lpd, vector<double> &hpd, vector<double> &lpr, vector<double> &hpr)
nm: Wavelet name.
lpd: Low Pass Decomposition Filter Coefficients.
hpd: High Pass Decomposition Filter Coefficients.
lpr: Low Pass Reconstruction Filter Coefficients.
hpr: High Pass Reconstruction Filter Coefficients.
All filters are vector<double>
objects and can be obtained by specifying the wavelet name. Currently, following Wavelets are available:
Daubechies : db1,db2,.., ,db15
Biorthogonal: bior1.1 ,bior1.3 ,bior1.5 ,bior2.2 ,bior2.4 ,bior2.6 ,bior2.8 ,bior3.1 ,bior3.3 ,bior3.5 ,bior3.7 ,bior3.9 ,bior4.4 ,bior5.5 ,bior6.8
Coiflets: coif1,coif2,coif3,coif4,coif5
Symmlets: sym2,........, sym10
1D Vector Manipulation
16. Downsampling: void downsamp(vector<double> &sig, int M, vector<double> &sig_d)
sig :: Signal to be Downsampled
M :: Downsampling factor
sig_d :: Downsampled signal
17. Upsampling: void upsamp(vector<double> &sig, int M, vector<double> &sig_u)
sig :: Signal to be Upsampled
M :: Upsampling factor
sig_u :: Upsampled signal
18. Periodic Extension: void* per_ext(vector<double> &sig, int a)
per_ext periodically extends the signal sig by value a in either direction.
19. Symmetric Extension: void* symm_ext(vector<double> &sig, int a)
symm_ext symmetrically extensd the signal sig by value a in either direction. This function needs refinement as it doesn't gives good results for smaller vectors.
2D Vector Manipulation
20. 2D Downsampling: void* downsamp2(vector<vector<double> > & vec1,vector<vector<double> > & vec2, int rows_dn, int cols_dn)
vec1 is the input, rows_dn and cols_dn are row and column downsampling factors. vec2 is the downsampled matrix.
21. 2D Upsampling: void* upsamp2(vector<vector<double> > & vec1,vector<vector<double> > & vec2, int rows_up, int cols_up)
vec1 is the input, rows_up and cols_up are row and column upsampling factors. vec2 is the upsampled matrix.
22. 2D Periodic Extension: void* per_ext2d(vector<vector<double> > &signal,vector<vector<double> > &temp2, int a)
signal is extended by a in all directions and the result is returned in 2D vector temp2
23. 2D Symmetric Extension: void* symm_ext2d(vector<vector<double> > &signal,vector<vector<double> > &temp2, int a)
signal is extended by a in all directions and the result is returned in 2D vector temp2