This package contains two DLLs for MSVC++ - one Debug and one Release version.

The list of required files in order to complie wavelet2d based programs-

Header File- wavelet2d.h

Import Library- wavelet2d.lib

Wavelet DLL - wavelet2d.dll

FFTW DLL - libfftw3-3.dll

Header file is in the source (’src’) folder. Wavelet Libraries are in the respective Debug and Release folders. FFTW DLL is in the FFTW3 folder. Alternatively, you may chose to install FFT library from www.fftw.org. The FFTW source codes are also available at FFTW website under GNU-GPL license.

In order to use wavelet libraries, the easiest way is to add import library (wavelet2d.lib) to additional dependency in your project which in turn will handle the DLLs for you. The two DLLs must be in your program path.If you are new to MSVC, you may want to learn more about DLL search path at

You may also chose to directly call DLLs from your program.Regardless of how you handle DLLs, mixing debug and release versions is not a good idea.Both versions are named wavelet2d.dll so putting them in system path is not a good idea either. Preferred way is to use Visual Studio project settings to link to the wavelet2d.lib file and put the release and debug wavelet2d dlls along with libfftw-3.3dll in the directory containing the respective release and debug executables of your project. Import library will open the DLLs.

If you use GCC compiler either through MSYS or from one of the IDEs(Codeblocks, Eclipse, QTcreator, Netbeans etc.),I have also added both debug and release versions of wavelet2d DLLs and wavelet2s static libraries. Required Files for MinGW DLLS-

Header Files- wavelet2d.h

Import Library- libwavelet2d.dll.a

Wavelet DLL - libwavelet2d.dll

FFTW DLL - libfftw3-3.dll (Import library is also included)

It is recommended that you link to the Release and Debug folders as they are. Once you link to import library and specify the folder location, wavelet import library should automatically open the two DLLs. Mixing Debug and Release versions shouldn’t pose any problems in this case.

Working with MinGW Static libraries is even more straightforward. You need to include wavelet2s.h header in your program , link to static *.a library and you are set.

This package contains two wavelet libraries- libwavelet2d.so.1.0 (shared) and libwavelet2s.a (static) compiled essentially from the same source code. Source code is available in the ’src’ folder.

You may need to link to header files that are included with their resepctive libraries. They are also available in the ’src’ folder.

You may want to install shared library in one of your existing paths to make compilation easier. You can create sym links once inside the folder( say /usr/local/lib) by using following commands

ln -sf libwavelet2d.so.1.0 libwavelet2d.so

ln -sf libwavelet2d.so.1.0 libwavelet2d.so.1

ldconfig

You will probably need superuser privileges to perform previous steps. If you don't have su privilege then you can move libwavelet2d.so.1.0 to your work folder or where your source code is, create sym links as before and then put your folder in the path during runtime.

ln -sf libwavelet2d.so.1.0 libwavelet2d.so

ln -sf libwavelet2d.so.1.0 libwavelet2d.so.1

export LD_LIBRARY_PATH=.

libwavelet2s.a Working with static library is pretty straightforward. You will only need to include wavelet2s.h in your program and specify the library (-lwavelet2s flag) , include path (-I[path to wavelet2s.h] flag) and library path (-L[path to libwavelet2s.a] flag).

These libraries are licensed under GNU-GPL v2.0 (or any later version). See COPYRIGHT and COPYING files for more information. These libraries statically and dynamically link to FFTW-3.2.2 static library, FFTW3-3.3 static libray and FFTw-3.2.2 dynamic libraries in different implementations. More information, fftw libraries and associated files for this version are available at www.fftw.org. I have not modified fftw source codes in any way shape or form so you may want to download copies of source code and other files from the FFTW website itself if you are so inclined. However, you will find FFTW3 licensing and copyright information in the fftw3 folder.

Copyright:

/*Copyright (C) 2011 Rafat Hussain

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 or any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

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.

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)]

A(J) is the approximation coefficient vector at the Jth level while D(n) are the detail coefficient vectors at the nth level. ’length’ contains the lengths of corresponding vectors. Last entry of the length vector is the length of the original signal.

flag :: Housekeeping vector. In this implementation it contains two values-

flag[0] 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

flag[1] - contains the decomposition levels.

Housekeeping vector is a double vector as it was originally meant to store more values than it currently does.

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)]

A(J) is the approximation coefficient vector at the Jth level while D(n) are the detail coefficient vectors at the nth level. ’length’ contains the lengths of corresponding vectors. Last entry of the length vector is the length of the original signal.

flag :: Housekeeping vector. In this implementation it contains two values-

flag[0] 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

flag[1] - contains the decomposition levels.

Housekeeping vector is a double vector as it was originally meant to store more values than it currently does.

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.

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.

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.

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.

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).

Convfft 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 fft which is implemented by convol function.

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.

1. dwt and dwt_sym functions are interchangeable in the following code as they take the same arguments.

2. Please make sure that right header file is included. Header file for dynamic libraries is wavelet2d.h and for static libraries, wavelet2s.h is used.

3. I’m using OPENCV to handle images as i already use OPENCV for other image processing work. You may want to use some simpler image libraries as OPENCV is a full image processing suite and is very bulky or you can just use 2D matrices/build your own image classes. Regardless, DWT/IDWT operations are more important than the choice of libraries.

cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl;

string nm; // nm will store the name of Wavelet Family

cin >> nm;

cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl;

char inp[50];

cin >> inp;

vector<double> sig;

ifstream sig_inp(inp);

if ( !sig_inp.good()){

cout << "The File doesn’t exist"<< endl;

exit(1);

}

while (sig_inp) {

double temp;

sig_inp >> temp;

sig.push_back(temp);

}

sig.pop_back();

vector<double> original;

original = sig;

cout << "Please Enter the Number of DWT Stages J :" << endl;

int J;

cin >> J ;

vector<double> dwt_output, flag;

vector<int> length1;

// perform J-Level DWT

dwt(sig, J, nm, dwt_output,flag, length1);

// Performing Linear Approximation by using only first 100 coefficients

// Coefficients in dwt_output are stored as following

// dwt_output =[ Appx(J-1) Detail(J-1) Detail(J-2) .... Detail(0)]

int n_coef = 100; // Number of significant coefficients

int n_non_sig= dwt_output.size() - n_coef; // Number of Coefficients that will

// be set to zero

dwt_output.erase(dwt_output.end()- n_non_sig,dwt_output.end());

// Deleting last n_non_sig coefficients and replacing them with zeros

dwt_output.insert(dwt_output.end(),n_non_sig,0);

ofstream linearsig("linsig.txt");

for (unsigned int i = 0; i < dwt_output.size(); i++) {

linearsig << dwt_output[i] << endl;

}

// Finding IDWT with approximated coefficients

vector<double> output;

idwt(dwt_output, flag,nm,output, length1);

unsigned int count = output.size();

ofstream gnulinappx("gnulinappx.dat");

for (unsigned int i = 0;i < count; i++) {

gnulinappx << output[i] << endl;

}

gnulinappx.close();

// Performing Non Linear Approximation by using only most

// significant coefficients

vector<double> dwt_output2, flag2;

vector<int> length2;

// perform J-Level DWT

dwt(sig, J, nm, dwt_output2,flag2,length2);

double thresh = 0.0;

vector<double> temp_dwtoutput;

for (unsigned int i =0; i < dwt_output2.size();i++){

double temp = abs(dwt_output2[i]);

temp_dwtoutput.push_back(temp);

}

/*

for (unsigned int i =0; i < temp_dwtoutput.size(); i++){

cout << temp_dwtoutput[i] << endl;

}

*/

findthresh(temp_dwtoutput,n_coef, thresh);

for (unsigned int i = 0; i < dwt_output2.size();i++){

double temp = abs(dwt_output2[i]);

if (temp < thresh){

dwt_output2.at(i) = 0.0;

}

}

/*

for (unsigned int i =0; i < dwt_output2.size(); i++){

cout << dwt_output2[i] << endl;

}

*/

ofstream nonlinsig("nonlinsig.txt");

for (unsigned int i = 0; i < dwt_output2.size(); i++) {

nonlinsig << dwt_output2[i] << endl;

}

// Finding IDWT with approximated coefficients

vector<double> output2;

idwt(dwt_output2, flag2,nm,output2, length2);

unsigned int count2 = output2.size();

cout << count2 << endl;

ofstream gnunlappx("gnunlappx.dat");

for (unsigned int i = 0;i < count2; i++) {

gnunlappx << output2[i] << endl;

}

gnunlappx.close();

return 0;

}

This program computes DWT of the 256-point signal and then uses only 100 coefficients to reconstruct the signal. In the first case, first 100 coefficients are are used to compute linear approximation. In the second case, 100 largest coefficients are used by calculating a threshold that separates largest 100 coefficients from the others.The wavelet used is db3 and the signal is decomposed and reconstructed over 5 stages of DWT/IDWT. The results are plotted below.

Figure 3.5 Console showing db3 5 level computation

Figure 3.6 Length 256 Piecewise Regular signal from WaveLab

In Linear Approximation case, only first 100 coefficients are retained. Others are set to zero.

Three level Stationary Wavelet Transform is computed using db2 wavelet. Approximation coefficients are stored only for the final (J=3) stage while the three detail coefficients( Horizontal, Vertical and Diagonal) are stored for each value. All 10 sets of coefficients are 512X512.