资源简介
DWT.h,实现小波变换的头文件
DWT.cpp,实现小波变换的源文件,里面有6个函数,可根据需要调用
DWT.cpp,实现小波变换的源文件,里面有6个函数,可根据需要调用
代码片段和文件信息
#include “StdAfx.h“
#include “DWT.h“
//多用8个的
const double h[4] = {0.4829629131450.8365163037380.224143868042-0.129409522551};
const double g[4] = {-0.129409522551-0.2241438680420.836516303738-0.482962913145};
void DWT_1D(double *Tint Ndouble *W)
{
//采用对称延拓
//采用0延拓
//采用周期延拓好
/*
周期延拓效果最好,重建结果无失真,对称延拓重建psnr达到60以上,0延拓达到50以上,都还不错。
*/
ASSERT(T != NULL);
ASSERT(W != NULL);
//
int K = N/2;
deque tempctempd;
//double vernier[4];
//
//计算
for(int i = 0;i < 2*K;i++)
{
tempc.push_back(T[i]);
}
tempd = tempc;
//
for(int i = 0;i < 3;i++)
{
//tempc.push_back(T[2*K-1-i]);
tempc.push_back(T[i]);//周期
//tempc.push_back(0);
}
for(int i = 0;i < 2;i++)
{
//tempd.push_front(T[i]);
tempd.push_front(T[2*K-1-i]);
//tempd.push_front(0);
}
//tempd.push_back(T[2*K-1]);
tempd.push_back(T[0]);
//tempd.push_back(0);
/////////
for(int i = 0;i < K;i++)
{
double sumcsumd;
sumc = sumd = 0;
for(int k = 0;k < 4;k++)
{
sumc += tempc[2*i+k]*h[k];
sumd += tempd[2*i+k]*g[k];
}
W[i] = sumc;
W[i+K] = sumd;
}
if(N%2!=0)
{
W[N-1] = T[N-1];
}
tempc.clear();
tempd.clear();
}
void DWT_2D(double *Imgint nWint nHdouble *W)
{
//一层小波变换
ASSERT(Img != NULL);
ASSERT(W != NULL);
//
double *T*W0;
//行变换
T = new double[nW];
W0 = new double[nW];
for(int i = 0;i < nH;i++)
{
for(int j = 0;j < nW;j++)
{
T[j] = Img[i*nW+j];
}
DWT_1D(TnWW0);
for(int j = 0;j < nW;j++)
{
W[i*nW+j] = W0[j];
}
}
delete []T;
delete []W0;
//列变换
T = new double[nH];
W0 = new double[nH];
for(int i = 0;i < nW;i++)
{
for(int j = 0;j < nH;j++)
{
T[j] = (double)W[j*nW+i];
}
DWT_1D(TnHW0);
for(int j = 0;j < nH;j++)
{
W[j*nW+i] = W0[j];
}
}
delete []T;
delete []W0;
}
void DWT_2D(double *Imgint nWint nHdouble *Wint n)
{
ASSERT(Img != NULL);
ASSERT(W != NULL);
////////////////////
int rr1r2;
r1 = (int)(log((double)nW)/log(2.0));
r2 = (int)(log((double)nH)/log(2.0));
r = min(r1r2);
ASSERT(n <= r);
////////////////////////////////////////////////////
for(int i = 0;i < nH;i++)
{
for(int j = 0;j < nW;j++)
{
W[i*nW+j] = Img[i*nW+j];
}
}
//////
double *T*DWT;
for(int i = 0;i < n;i++)
{
int hw;
h = (int)((double)nH/pow(2.0(double)i));
w = (int)((double)nW/pow(2.0(double)i));
///////////////////////////////////////
T = new double[h*w];
DWT = new double[h*w];
for(int j = 0;j < h;j++)
{
for(int k = 0;k < w;k++)
{
T[j*w+k] = W[j*nW+k];
}
}
DWT_2D(TwhDWT);
for(int j = 0;j < h;j++)
{
for(int k = 0;k < w;k++)
{
W[j*nW+k] = DWT[j*w+k];
}
}
delete []T;
delete []DWT;
///////////////////////////////////////
}
}
void IDWT_1D(double *Tint Ndouble *W)
{
//反变换,从W到T
ASSERT(T != NULL);
ASSERT(W != NULL);
//
int K = N/
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1289728 2009-10-26 20:37 DwtImg.exe
文件 5850 2009-10-17 20:58 DWT.cpp
文件 390 2009-09-21 09:55 DWT.h
----------- --------- ---------- ----- ----
1295968 3
- 上一篇:PIC单片机完成的电子密码锁
- 下一篇:福建师范大学历年算法考卷
评论
共有 条评论