opencv小波变换代码

上传人:公**** 文档编号:492652647 上传时间:2023-07-30 格式:DOC 页数:7 大小:98KB
返回 下载 相关 举报
opencv小波变换代码_第1页
第1页 / 共7页
opencv小波变换代码_第2页
第2页 / 共7页
opencv小波变换代码_第3页
第3页 / 共7页
opencv小波变换代码_第4页
第4页 / 共7页
opencv小波变换代码_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《opencv小波变换代码》由会员分享,可在线阅读,更多相关《opencv小波变换代码(7页珍藏版)》请在金锄头文库上搜索。

1、提供函数 DWT() 和 IDWT() ,前者完成任意层次的小波变换,后者完成任意层次的小波逆变 换。输入图像要求必须是单通道浮点图像,对图像大小也有要求( 1 层变换: w,h 必须是 2 的倍数; 2 层变换: w,h 必须是 4 的倍数; 3 层变换: w,h 必须是 8 的倍数 ),变换后的结 果直接保存在输入图像中。1、函数参数简单,图像指针 pImage 和变换层数 nLayer 。2、一个函数直接完成多层次二维小波变换,尽量减少下标运算,避免不必要的函数调用, 以提高执行效率。3、变换过程中, 使用了一个指针数组 pData 用于保存每行数据的起始位置, pRow 和 pColu

2、mn 用于保存一行和一列临时数据,用于奇偶分离或合并,内存消耗较少/ 二维离散小波变换(单通道浮点图像) void DWT(IplImage *pImage, int nLayer) / 执行条件if (pImage)if (pImage-nChannels = 1 & pImage-depth = IPL_DEPTH_32F &(pImage-width nLayer) width & (pImage-height nLayer) height) inti, x, y, n;float fValue = 0; floatfRadius= sqrt(2.0f);intnWidth= pImag

3、e-width;intnHeight= pImage-height;intnHalfW= nWidth / 2;intnHalfH= nHeight / 2;float *pData= new float*pImage-height;float *pRow= new floatpImage-width;float *pColumn = new floatpImage-height; for (i = 0; i height; i+) pDatai = (float*) (pImage-imageData + pImage-widthStep * i);/ 多层小波变换for (n = 0; n

4、 nLayer; n+, nWidth /= 2, nHeight /= 2, nHalfW /= 2, nHalfH /= 2) / 水平变换for (y = 0; y nHeight; y+) / 奇偶分离 memcpy(pRow, pDatay, sizeof(float) * nWidth);for (i = 0; i nHalfW; i+)x = i * 2; pDatayi = pRowx;pDataynHalfW + i = pRowx + 1;/ 提升小波变换for (i = 0; i nHalfW - 1; i+)fValue = (pDatayi + pDatayi + 1

5、) / 2; pDataynHalfW + i -= fValue;fValue = (pDataynHalfW - 1 + pDataynHalfW - 2) / 2; pDataynWidth - 1 -= fValue;fValue = (pDataynHalfW + pDataynHalfW + 1) / 4; pDatay0 += fValue;for (i = 1; i nHalfW; i+)fValue = (pDataynHalfW + i + pDataynHalfW + i - 1) / 4; pDatayi += fValue;/ 频带系数for (i = 0; i nH

6、alfW; i+) pDatayi *= fRadius; pDataynHalfW + i /= fRadius;/ 垂直变换for (x = 0; x nWidth; x+)/ 奇偶分离for (i = 0; i nHalfH; i+)y = i * 2; pColumni = pDatayx;pColumnnHalfH + i = pDatay + 1x;for (i = 0; i nHeight; i+) pDataix = pColumni;/ 提升小波变换for (i = 0; i nHalfH - 1; i+)fValue = (pDataix + pDatai + 1x) /

7、2; pDatanHalfH + ix -= fValue;fValue = (pDatanHalfH - 1x + pDatanHalfH - 2x) / 2; pDatanHeight - 1x -= fValue;fValue = (pDatanHalfHx + pDatanHalfH + 1x) / 4; pData0x += fValue;for (i = 1; i nHalfH; i+) fValue = (pDatanHalfH + ix + pDatanHalfH + i - 1x) / 4; pDataix += fValue;/ 频带系数for (i = 0; i nCha

8、nnels = 1 & pImage-depth = IPL_DEPTH_32F &(pImage-width nLayer) width & (pImage-height nLayer) height)inti, x, y, n;floatfValue =0;floatfRadius= sqrt(2.0f);intnWidth= pImage-width (nLayer -1);intnHeight= pImage-height (nLayer- 1);int nHalfW int nHalfH float *pData float *pRow= nWidth / 2;= nHeight /

9、 2;= new float*pImage-height;= new floatpImage-width;float *pColumn = new floatpImage-height;for (i = 0; i height; i+)pDatai = (float*) (pImage-imageData + pImage-widthStep * i);/ 多层小波恢复for (n = 0; n nLayer; n+, nWidth *= 2, nHeight *= 2, nHalfW *= 2, nHalfH *= 2) / 垂直恢复for (x = 0; x nWidth; x+) / 频

10、带系数for (i = 0; i nHalfH; i+)pDataix /= fRadius;pDatanHalfH + ix *= fRadius;/ 提升小波恢复fValue = (pDatanHalfHx + pDatanHalfH + 1x) / 4; pData0x -= fValue;for (i = 1; i nHalfH; i+)fValue = (pDatanHalfH + ix + pDatanHalfH + i - 1x) / 4; pDataix -= fValue;for (i = 0; i nHalfH - 1; i+)fValue = (pDataix + pDa

11、tai + 1x) / 2; pDatanHalfH + ix += fValue;fValue = (pDatanHalfH - 1x + pDatanHalfH - 2x) / 2; pDatanHeight - 1x += fValue;/ 奇偶合并for (i = 0; i nHalfH; i+)y = i * 2;pColumny = pDataix;pColumny + 1 = pDatanHalfH + ix;for (i = 0; i nHeight; i+)pDataix = pColumni;/ 水平恢复for (y = 0; y nHeight; y+)/ 频带系数for

12、 (i = 0; i nHalfW; i+) pDatayi /= fRadius; pDataynHalfW + i *= fRadius;/ 提升小波恢复fValue = (pDataynHalfW + pDataynHalfW + 1) / 4; pDatay0 -= fValue;for (i = 1; i nHalfW; i+)fValue = (pDataynHalfW + i + pDataynHalfW + i - 1) / 4; pDatayi -= fValue;for (i = 0; i nHalfW - 1; i+) fValue = (pDatayi + pDatayi + 1) / 2; pDataynHalfW + i += fValue;fValue = (pDataynHalfW - 1 + pDataynHalfW - 2) / 2; pDataynWidth - 1 += fV alue;/ 奇偶合并for (i = 0; i nHalfW; i+) x = i * 2; pRowx = pDatayi; pRowx + 1 = pDataynHalfW + i;memcpy(pDa

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号