Click here to Skip to main content
13,708,868 members
Click here to Skip to main content
Add your own
alternative version

Stats

40K views
2.1K downloads
24 bookmarked
Posted 16 May 2012
Licenced CPOL

Multidimensional Discrete Wavelet Transform

, 16 May 2012
Rate this:
Please Sign up or sign in to vote.
The implementation of multidimensional wavelet transform

Introduction 

I give a class of multidimensional discrete wavelet transform.  This class can analyze the multidimensional input signal and synthesize it after process.  The input signal can be one dimensional signal(like a wave), two dimensional signal(like a image) or multidimensional signal. 

Background  

You should know the discrete wavelet transform(DWT) before using this class. The following figure shows the basic idea of the DWT. 

After DWT, the input signal is analyzed into wavelet coefficients. The wavelet coefficients can be processed and synthesize  into the output signal. There are four filters in this whole process: high pass filters, H and H'; low pass filters, L and L'; 

After DWT, the input signal is analyzed into wavelet coefficients. The wavelet coefficients can be processed and synthesize  into the output signal. There are four filters in this whole process: high pass filters, H and H'; low pass filters, L and L'; 

Using the code 

The class is shown below. 

//
// The wavelet transform class
//
class WaveletAnalysis{
public:
// the construction
	WaveletAnalysis(vector<double> input,vector<unsigned int> dim,unsigned int level,
		vector<double> h0,vector<double> h1,vector<double> h2,vector<double> h3);
	~WaveletAnalysis(void);

private:
// The four filters: L(H0),H(H1),L'(H2),H'(H3)
	CFilterFunc funcH0,funcH1,funcH2,funcH3;

// The decomposition levels
	unsigned int level;
// The buffer which save the signal and the wavelet coefficients
	vector<double> scalevalues;
	vector<double> waveletvalues;

	vector<double> *inputvalues;
	vector<double> *outputvalues;
	vector<unsigned int> offsets;
	vector<unsigned int> lens;

// The multidimensional lengths
	vector<unsigned int> dimensions;

public:
	void resetlevel(unsigned int level);
	void resetinput(vector<double> input,vector<unsigned int> ds);

//DWT
	void transform();
//iDWT
	void itransform();

	double getOutputValue(vector<unsigned int> ord){
		offsets = ord;
		unsigned int offset = getOffset();
		return (*outputvalues)[offset];}
//The process between the DWT and iDWT
	void process();
private:
	typedef void (WaveletAnalysis::*FuncInWhile)(void *);
	void whileProcess(FuncInWhile func,void* parameter);

	void initOffsetsAndLens(unsigned int level);
	void initOutput(void *v);

	void reconstructOneDimension(void * d);
	void analyzeOneDimension(void * d);

	inline void copyInput2Output(void *);
	inline void copyInput2OuputOnDim(void *dim);

	inline void swapVectorPointer();
	unsigned int getOffset();
};
// The main process of the DWT and iDWT

void WaveletAnalysis::transform(){
	inputvalues = &scalevalues;
	outputvalues = &waveletvalues;

	for(unsigned int l = 0; l < level; ++l){
		for(unsigned int d = 0; d < dimensions.size(); d++){
			initOffsetsAndLens(l);
			lens[d] = lens[d] >> 1;
			whileProcess(&WaveletAnalysis::analyzeOneDimension,&d);
			swapVectorPointer();
		}

		initOffsetsAndLens(l);
		whileProcess(&WaveletAnalysis::copyInput2Output,NULL);
		swapVectorPointer();

		initOffsetsAndLens(l+1);
		whileProcess(&WaveletAnalysis::copyInput2Output,NULL);
		swapVectorPointer();
	}
}

void WaveletAnalysis::itransform(){
	swapVectorPointer();

	for(unsigned int l = level; l > 0; --l){
		for(int d = dimensions.size() - 1; d >=0 ; d--){
			initOffsetsAndLens(l-1);
			whileProcess(&WaveletAnalysis::initOutput,0);

			initOffsetsAndLens(l-1);
			lens[d] = lens[d] >> 1;

			whileProcess(&WaveletAnalysis::reconstructOneDimension,&d);
			swapVectorPointer();

			initOffsetsAndLens(l-1);
			whileProcess(&WaveletAnalysis::copyInput2Output,NULL);
			swapVectorPointer();
		}
	}
}   

The inputs of the class are four kinds of parameters:

1.The input signal. 

2.The dimensional length of this multidimensional signals. 

3.The decomposition level. 

4.The four filters. 

Take a two dimensional image for example:

The input signal is:  

The dimensional length is dimensions: 

// the multidimensional lengths
vector<unsigned int> dimensions; 
dimensions.push_back(512);
dimensions.push_bask(512);  

The decomposition level is 5.

The four filters are Haar filters:

// Haar wavelet
vector<double> h0, h1,h2,h3;
double sqr = sqrtf(2.0);
h0.push_back(0.5*sqr);
h0.push_back(0.5*sqr);
h1.push_back(-0.5*sqr );
h1.push_back(0.5*sqr );
h2.push_back(0.5*sqr);
h2.push_back(0.5*sqr);
h3.push_back(-0.5*sqr );
h3.push_back(0.5*sqr ); 

The result of DWT is:

I erase the high frequency coefficients and iDWT the signal the output is shown below:

Points of Interest

This class can analyze the signal of any dimensions. The second parameter defines the length of each dimension. The input signal(input signal) should be as long as the second parameter defined.

History

Version 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

lxdfigo
Student Institute of Software, Chinese Academy of Sciences
China China
No Biography provided

Comments and Discussions

 
Questiondoes it support noisy analysis? Pin
11-Jul-17 16:08
member11-Jul-17 16:08 
Answer...reverse engineering Pin
JaimeAstroSwe8-Oct-14 2:30
memberJaimeAstroSwe8-Oct-14 2:30 
Questionexcellnt Pin
hspbh7-Nov-13 20:45
memberhspbh7-Nov-13 20:45 
Questionthe link doesn't work Pin
lqzhu27-Mar-13 14:42
memberlqzhu27-Mar-13 14:42 
The link is broken. Would you send me a copy of this library? My email: zlq_26@163.com
Thank you.
QuestionExcellent Pin
stchalon4-Dec-12 10:47
memberstchalon4-Dec-12 10:47 
GeneralMy vote of 5 Pin
Jasmine250121-May-12 9:50
memberJasmine250121-May-12 9:50 
QuestionBroken Link Pin
LaxmikantYadav16-May-12 9:10
memberLaxmikantYadav16-May-12 9:10 
GeneralMy vote of 4 Pin
Sergio Andrés Gutiérrez Rojas16-May-12 6:58
memberSergio Andrés Gutiérrez Rojas16-May-12 6:58 
QuestionMissing images Pin
Amarnath S16-May-12 1:13
groupAmarnath S16-May-12 1:13 
AnswerRe: Missing images Pin
ednrg16-May-12 4:06
memberednrg16-May-12 4:06 
GeneralRe: Missing images Pin
embrabbit8-Sep-12 3:41
memberembrabbit8-Sep-12 3:41 
GeneralMy vote of 5 Pin
MLSHWJZ16-May-12 0:49
memberMLSHWJZ16-May-12 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.180920.1 | Last Updated 16 May 2012
Article Copyright 2012 by lxdfigo
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid