小波变换 C opencv 实现文档格式.docx
《小波变换 C opencv 实现文档格式.docx》由会员分享,可在线阅读,更多相关《小波变换 C opencv 实现文档格式.docx(10页珍藏版)》请在冰豆网上搜索。
![小波变换 C opencv 实现文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/13/07d694cb-301e-4dde-8b47-6e772bd35779/07d694cb-301e-4dde-8b47-6e772bd357791.gif)
Matsrc=Mat_&
lt;
float&
gt;
(_src);
Matdst=Mat:
:
zeros(src.rows,src.cols,src.type());
intN=src.rows;
intD=src.cols;
///高通低通滤波器
MatlowFilter;
MathighFilter;
wavelet(_wname,lowFilter,highFilter);
///小波变换
intt=1;
introw=N;
intcol=D;
while(t&
=_level)
{
///先进行行小波变换
for(inti=0;
i&
row;
i++)
///取出src中要处理的数据的一行
MatoneRow=Mat:
zeros(1,col,src.type());
for(intj=0;
j&
col;
j++)
oneRow.at&
(0,j)=src.at&
(i,j);
}
oneRow=waveletDecompose(oneRow,lowFilter,highFilter);
///将src这一行置为oneRow中的数据
dst.at&
(i,j)=oneRow.at&
(0,j);
#if0
//normalize(dst,dst,0,255,NORM_MINMAX);
IplImagedstImg1=IplImage(dst);
cvSaveImage("
dst.jpg"
&
dstImg1);
#endif
///小波列变换
///取出src数据的一行输入
MatoneCol=Mat:
zeros(row,1,src.type());
for(inti=0;
i++)
oneCol.at&
(i,0)=dst.at&
oneCol=(waveletDecompose(oneCol.t(),lowFilter,highFilter)).t();
(i,j)=oneCol.at&
(i,0);
IplImagedstImg2=IplImage(dst);
dstImg2);
///更新
row/=2;
col/=2;
t++;
src=dst;
returndst;
}
///小波逆变换
MatIWDT(constMat&
introw=N/std:
pow(2.,_level-1);
intcol=D/std:
pow(2.,_level-1);
while(row&
=N&
&
col&
=D)
///小波列逆变换
(i,0)=src.at&
oneCol=(waveletReconstruct(oneCol.t(),lowFilter,highFilter)).t();
///行小波逆变换
(0,j)=dst.at&
oneRow=waveletReconstruct(oneRow,lowFilter,highFilter);
row*=2;
col*=2;
////////////////////////////////////////////////////////////////////////////////////////////
///调用函数
///生成不同类型的小波,现在只有haar,sym2
voidwavelet(conststring_wname,Mat&
_lowFilter,Mat&
_highFilter)const
if(_wname=="
haar"
||_wname=="
db1"
)
intN=2;
_lowFilter=Mat:
zeros(1,N,CV_32F);
_highFilter=Mat:
_lowFilter.at&
(0,0)=1/sqrtf(N);
(0,1)=1/sqrtf(N);
_highFilter.at&
(0,0)=-1/sqrtf(N);
if(_wname=="
sym2"
intN=4;
floath[]={-0.483,0.836,-0.224,-0.129};
floatl[]={-0.129,0.224,0.837,0.483};
N;
(0,i)=l[i];
(0,i)=h[i];
///小波分解
MatwaveletDecompose(constMat&
_src,constMat&
_lowFilter,constMat&
assert(_src.rows==1&
_lowFilter.rows==1&
_highFilter.rows==1);
assert(_src.cols&
=_lowFilter.cols&
_src.cols&
=_highFilter.cols);
Mat&
src=Mat_&
lowFilter=Mat_&
(_lowFilter);
highFilter=Mat_&
(_highFilter);
///频域滤波,或时域卷积;
ifft(fft(x)*fft(filter))=cov(x,filter)
Matdst1=Mat:
zeros(1,D,