did someone tried to implement DWT in opencv or in C++? I saw older posts on this subject and i didn't find them useful for me, because I need a approximation coefficient and details as a result of wavelet transformation.
I tried to add this (http://wavelet2d.sourceforge.net/) to my project but it's not working as well as planned.
And this is to simple, because as a result parameters i need approximation coefficient and details:
void haar1(float *vec, int n, int w)
{
int i=0;
float *vecp = new float[n];
for(i=0;i<n;i++)
vecp[i] = 0;
w/=2;
for(i=0;i<w;i++)
{
vecp[i] = (vec[2*i] + vec[2*i+1])/sqrt(2.0);
vecp[i+w] = (vec[2*i] - vec[2*i+1])/sqrt(2.0);
}
for(i=0;i<(w*2);i++)
vec[i] = vecp[i];
delete [] vecp;
}
void haar2(float **matrix, int rows, int cols)
{
float *temp_row = new float[cols];
float *temp_col = new float[rows];
int i=0,j=0;
int w = cols, h=rows;
while(w>1 || h>1)
{
if(w>1)
{
for(i=0;i<h;i++)
{
for(j=0;j<cols;j++)
temp_row[j] = matrix[i][j];
haar1(temp_row,cols,w);
for(j=0;j<cols;j++)
matrix[i][j] = temp_row[j];
}
}
if(h>1)
{
for(i=0;i<w;i++)
{
for(j=0;j<rows;j++)
temp_col[j] = matrix[j][i];
haar1(temp_col, rows, h);
for(j=0;j<rows;j++)
matrix[j][i] = temp_col[j];
}
}
if(w>1)
w/=2;
if(h>1)
h/=2;
}
delete [] temp_row;
delete [] temp_col;
}
So can someone help me find dwt implemented in C++ or point me how to extract from above code coefficients. Thanks
Suggestion: I don't suggest you to implement dwt from scratch, it is very hard to meet your demands. If you really need it's cpp version in your job, I recommend you try PyWavelets, whose basic functions of dwt are implementd in C, so you can migrate it to your program easily. Otherwise, you can also verify your thoughts with python first rather than take a risk of paying useless efforts.
Here is one of my implementation of dwt which support many kinds of wavelet filter, it works but dosen't work well. With the increasing of level, the reconstrusion being more and more blurred.
If you want to change the wavelet filter, you can use matlab (
wfilters(wname)
) or pick from PyWavelets's source code, and it also gives the rule to get totall 4 filter from these coefficients.I see that there's very few code examples for wavelet in java, especially if you're using openCV. I had to use wavelet in java with openCV and I used the C code from @la luvia and converted to java.
There was a lot of trouble while translating the code, because it had a lot of diferences in the openCV methods and ways of using it. This book helped me a lot in the process too.
I hope this code and the book give some perspective of how to use the lib and few diferences between the C and Java.
Here's the code:
Hope it's useful.
Here is direct and inverse Haar Wavelet transform (used for filtering):
Here is another implementation of Wavelet transform in OpenCV from Mahavir:
Hope someone finds it useful!