WFilter.cpp
上传用户:aqingfeng
上传日期:2014-03-25
资源大小:1839k
文件大小:6k
- // WFilter.cpp: implementation of the CWFilter class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "小波变换.h"
- #include "WFilter.h"
- #include "WvltTrans.h"
- #include <math.h>
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CWFilter::CWFilter()
- {
- }
- CWFilter::~CWFilter()
- {
- }
- /**********************************************************************************
- *函数描述: LPass_Filter实现小波变换的低通滤波,减少图像的边缘信息,使图像更加平滑*
- *函数参数: unsigned char **pData:图像小波变换后的小波系数矩阵 *
- * int nHeight :图像属性参数,数值为原始图像的高度值 *
- * int nWidth :图像属性参数,数值为原始图像的宽度值 *
- * int nLayer :低通滤波器的滤波阶数,数值为小波变换的层数 *
- *函数返回值:函数无返回值,小波系数参数是利用指针进行调用 *
- **********************************************************************************/
- void CWFilter::LPass_Filter(short **pData, int nHeight, int nWidth, int nLayer, int scale)
- {
- short **spOriginData, **spTransData0, **spTransData1;
- int iHeight = nHeight, iWidth = nWidth;
- spOriginData = pData;
- spTransData0 = new short *[nHeight];
- spTransData1 = new short *[nHeight];
- m_FilterData = new short * [nHeight];
- for(int i = 0; i < nHeight; i ++)
- {
- spTransData0[i] = new short [nWidth];
- spTransData1[i] = new short [nWidth];
- m_FilterData[i] = new short [nWidth];
- for(int j = 0; j < nWidth; j ++)
- {
- m_FilterData[i][j] = 0;
- }
- }
- CWvltTrans *Trans;
- Trans->DWT_TriLayers(spOriginData, spTransData0, spTransData1, nHeight, nHeight/2, nWidth, nWidth/2, nLayer, 1.414);
- for(i = 0; i < (int) nHeight / (4 * scale); i ++)
- {
- for(int j = 0; j < (int) nWidth / (4 * scale); j ++)
- {
- m_FilterData[i][j] = spTransData1[i][j];
- }
- }
- delete spTransData0;
- delete spTransData1;
- DWT_Inverse(iHeight, iWidth, 3);
- }
- /****************************************************************************
- *函数描述: HPass_Filter完成图像的高通滤波处理,得到图像的边缘信息 *
- *函数参数: short **pData :二维指针,存放正则化后的小波系数 *
- * int nHeight :图像属性参数,数值为原始图像的高度值 *
- * int nHeight_H :图像属性参数,数值为原始图像高度值的一半 *
- * int nWidth :图像属性参数,数值为原始图像的宽度值 *
- * int nLayer :小波变换的层数 *
- *函数返回值:函数无返回值,小波系数参数是利用指针进行调用 *
- *****************************************************************************/
- void CWFilter::HPass_Filter(short **pData, int nHeight, int nWidth, int nLayer)
- {
- short **spOriginData, **spTransData0, **spTransData1;
- int iHeight = nHeight, iWidth = nWidth;
- spOriginData = pData;
- spTransData0 = new short *[nHeight];
- spTransData1 = new short *[nHeight];
- m_FilterData = new short * [nHeight];
- for(int i = 0; i < nHeight; i ++)
- {
- spTransData0[i] = new short [nWidth];
- spTransData1[i] = new short [nWidth];
- m_FilterData[i] = new short [nWidth];
- for(int j = 0; j < nWidth; j ++)
- {
- m_FilterData[i][j] = 0;
- }
- }
- CWvltTrans *Trans;
- Trans->DWT_TriLayers(spOriginData, spTransData0, spTransData1, nHeight, nHeight/2, nWidth, nWidth/2, nLayer, 1.414);
- for(i = (int) nHeight / 8; i < nHeight; i ++)
- {
- for(int j = (int) nWidth / 8; j < nWidth ; j ++)
- {
- m_FilterData[i][j] = spTransData1[i][j];
- }
- }
- delete spTransData0;
- delete spTransData1;
- DWT_Inverse(iHeight, iWidth, 3);
- }
- /************************************************************************
- *函数描述: DWT_Inverse完成若干层小波变换的逆变换操作 *
- *函数参数: int nHeight :图像属性参数,数值为原始图像的高度值 *
- * int nWidth :图像属性参数,数值为原始图像的宽度值 *
- * int nLayer :小波变换的层数 *
- *************************************************************************/
- void CWFilter::DWT_Inverse(int nHeight, int nWidth, int nLayer)
- {
- int iHeight = nHeight / 4, iWidth = nWidth / 4;
- int iHeight_H = iHeight / 2, iWidth_H = iWidth / 2;
- short **spTransData0, **spTransData1;
- spTransData0 = new short * [nHeight];
- spTransData1 = new short * [nHeight];
-
- for(int i = 0; i < nHeight; i++)
- {
- spTransData0[i] = new short [nWidth];
- spTransData1[i] = new short [nWidth];
- }
- CWvltTrans WTrans;
- for( i = nLayer; i >= 1; i--)
- {
- WTrans.DWTi_Once(spTransData0, spTransData1, m_FilterData, iHeight, iHeight_H, iWidth, iWidth_H, i, 1.414);
- iHeight <<= 1; iWidth <<= 1;
- iHeight_H = iHeight / 2; iWidth_H = iWidth / 2;
- }
- for(int y = 0; y < nHeight; y++)
- {
- for(int x = 0; x < nWidth; x++)
- {
- m_FilterData[y][x] = spTransData0[y][x];
- }
- }
-
-
- }
- /****************************************************************************
- *函数描述: HPass_Filter完成图像的高通滤波处理,得到图像的边缘信息 *
- *函数参数: short **pData :二维指针,存放正则化后的小波系数 *
- * int nHeight :图像属性参数,数值为原始图像的高度值 *
- * int nHeight_H :图像属性参数,数值为原始图像高度值的一半 *
- * int nWidth :图像属性参数,数值为原始图像的宽度值 *
- * int nLayer :小波变换的层数 *
- *函数返回值:函数无返回值,小波系数参数是利用指针进行调用 *
- *****************************************************************************/
- void CWFilter::HPass_Filter2(short **pData, int nHeight, int nWidth, int nLayer)
- {
- short **spOriginData, **spTransData0, **spTransData1;
- int iHeight = nHeight, iWidth = nWidth;
- spOriginData = pData;
- spTransData0 = new short *[nHeight];
- spTransData1 = new short *[nHeight];
- m_FilterData = new short * [nHeight];
- for(int i = 0; i < nHeight; i ++)
- {
- spTransData0[i] = new short [nWidth];
- spTransData1[i] = new short [nWidth];
- m_FilterData[i] = new short [nWidth];
- }
- CWvltTrans *Trans;
- Trans->DWT_TriLayers(spOriginData, spTransData0, spTransData1, nHeight, nHeight/2, nWidth, nWidth/2, nLayer, 1.414);
- for(i = 0; i < nHeight; i ++)
- {
- for(int j = 0; j < nWidth ; j ++)
- {
- m_FilterData[i][j] = spTransData1[i][j];
- if(i < nHeight / 8 && j < nWidth / 8)
- m_FilterData[i][j] /= 2;
- }
- }
- delete spTransData0;
- delete spTransData1;
- DWT_Inverse(iHeight, iWidth, 3);
- }