1、 Mat src = Mat_<float>(_src); Mat dst = Mat:zeros( src.rows, src.cols, src.type() ); int N = src.rows; int D = src.cols; / 高通低通滤波器 Mat lowFilter; Mat highFilter; wavelet( _wname, lowFilter, highFilter ); / 小波变换 int t=1; int row = N; int col = D; while( t&=_level ) /先进行行小波变换 for( int i=0; i&row
2、; i+ ) / 取出src中要处理的数据的一行 Mat oneRow = Mat:zeros( 1,col, src.type() ); for ( int j=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);#if 0 /normalize( dst, dst, 0, 255, NORM_MINMAX ); IplImag
3、e dstImg1 = IplImage(dst); cvSaveImage( dst.jpg, &dstImg1 );#endif / 小波列变换 / 取出src数据的一行输入 Mat oneCol = Mat:zeros( row, 1, src.type() ); for ( int i=0; i+ ) oneCol.at&(i,0) = dst.at& oneCol = ( waveletDecompose( oneCol.t(), lowFilter, highFilter ) ).t();(i,j) = oneCol.at&(i,0); IplImage dstImg2 = Ipl
4、Image(dst);dstImg2 ); / 更新 row /= 2; col /=2; t+; src = dst; return dst;/ 小波逆变换Mat IWDT( const Mat & int row = N/std:pow( 2., _level-1); int col = D/std:pow(2., _level-1); while ( row&=N & col&=D ) / 小波列逆变换(i,0) = src.at& oneCol = ( waveletReconstruct( oneCol.t(), lowFilter, highFilter ) ).t(); /行小波
5、逆变换(0,j) = dst.at& oneRow = waveletReconstruct( oneRow, lowFilter, highFilter ); row *= 2; col *= 2;/ 调用函数/ 生成不同类型的小波,现在只有haar,sym2void wavelet( const string _wname, Mat &_lowFilter, Mat &_highFilter )const if ( _wname=haar | _wname=db1 ) int N = 2; _lowFilter = Mat:zeros( 1, N, CV_32F ); _highFilte
6、r = Mat: _lowFilter.at&(0, 0) = 1/sqrtf(N);(0, 1) = 1/sqrtf(N); _highFilter.at&(0, 0) = -1/sqrtf(N); if ( _wname =sym2 int N = 4; float h = -0.483, 0.836, -0.224, -0.129 ; float l = -0.129, 0.224, 0.837, 0.483 ;N;(0, i) = li;(0, i) = hi;/ 小波分解Mat waveletDecompose( const Mat &_src, const Mat &_lowFil
7、ter, const Mat & 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) Mat dst1 = Mat:zeros( 1, D,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1