⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waveletdoc.cpp

📁 this walet there is pictures in it you can debug it
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		spTransData1[i] = new short [biWidth];
		m_WaveletCoeff[i] = new short [biWidth];
	}
	//创建图像小波变换类
	CWaveletTrans *pTrans;
	//从设备缓存中获取原始图像数据
	for (i=0;i<=2;i++)
	{
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);
		}
	}
	//完成一次图像小波变换
	pTrans->DWT_Once(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,1,1.414);
	//允许图像复原操作标志
	m_bOnce = TRUE;
	m_bTwice = FALSE;
	m_bTribl = FALSE;
	//m_bOnce = m_bOnce & ~m_bTwice & ~m_bTribl & ~m_bFilter;
	MaxPixVal=spTransData1[0][0];
	MinPixVal=spTransData1[0][0];
	for( y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			if(MaxPixVal<spTransData1[y][x])
				MaxPixVal=spTransData1[y][x];
			if(MinPixVal>spTransData1[y][x])
				MinPixVal=spTransData1[y][x];
			//m_WvltCoeff[y][x] = spTransData1[y][x];
            
		}
	}
	Diff=MaxPixVal-MinPixVal;
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
		//因为小波变换后的小波系数有可能超过255甚至更多,那么就将
		//小波系数的范围映射到0~255区间内,以后出现类似的处理,目的都是一样的
			fTempBufforDisp=spTransData1[biHeight-1-y][x];
			
			fTempBufforDisp-=MinPixVal;
			long num;
			num=1<<(lpBitmapInfoHeader->biBitCount/3);

			fTempBufforDisp*=(num-1);
			fTempBufforDisp/=Diff;
			
			cur= y*biAlign+3*x;		//current pixel
			m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
			m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
         	/*
			m_pTransfered[cur]	= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
			*/
		}
	}
	}
	//显示图像的小波系数
	UpdateAllViews(NULL);
	//删除临时的数据空间
	delete spOriginData;
	delete spTransData0;
	delete spTransData1;
	return;	
}

void CWaveletDoc::OnWaveletTwo() 
{
//读取数字图像的文件头,获取图像的属性参数
	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;
	if(m_pTransfered==NULL)
	{
		m_pTransfered=(unsigned char*) malloc (bmSize);
		m_pstore=new short [bmSize];
	}
	if(m_pTransfered==NULL)
		return;
	//图像矩阵坐标与像素数值
	int x,y,cur;
	unsigned char tempR, tempG, tempB;
	float fTempBufforDisp;
	short MaxPixVal,MinPixVal,Diff;
	short **spOriginData, **spTransData0, **spTransData1;
	//分配数据空间
	spOriginData = new short* [biHeight];
	spTransData0 = new short* [biHeight];
	spTransData1 = new short* [biHeight];
	m_WaveletCoeff	= new short * [biHeight];

	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];
		spTransData1[i] = new short [biWidth];
		m_WaveletCoeff[i] = new short [biWidth];
	}
	//创建图像小波变化类
	CWaveletTrans *pTrans;
	//从设备缓存中获取原始图像数据
	for (i=0;i<=2;i++)
	{
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);
			/*
			tempB=lpData[cur];
			tempG=lpData[cur+1];
			tempR=lpData[cur+2];
			spOriginData[biHeight-1-y][x]=(short)(0.3*tempR+0.59*tempG+0.11*tempB);  //no problem
			*/
		}
	}
	//完成图像的两次小波变换
	pTrans->DWT_Two(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,2,1.414);
	//允许图像复原操作标志
	m_bOnce = FALSE;
	m_bTribl = FALSE;
	m_bTwice = TRUE;
	//m_bTwice = m_bTwice & ~m_bTribl & ~m_bOnce & ~m_bFilter;
	MaxPixVal=spTransData1[0][0];
	MinPixVal=spTransData1[0][0];
	//计算得到图像小波系数的极大值与极小值
	for( y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			if(MaxPixVal<spTransData1[y][x])
				MaxPixVal=spTransData1[y][x];
			if(MinPixVal>spTransData1[y][x])
				MinPixVal=spTransData1[y][x];
			//m_WvltCoeff[y][x] = spTransData1[y][x];
		}
	}
	//计算获得小波系数的极值差
	Diff=MaxPixVal-MinPixVal;
	//小波系数经过处理后,放入显示缓存中
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
		//因为小波变换后的小波系数有可能超过255甚至更多,那么就将
		//小波系数的范围映射到0~255区间内,以后出现类似的处理,目的都是一样的
			fTempBufforDisp=spTransData1[biHeight-1-y][x];
			fTempBufforDisp-=MinPixVal;
			long num;
			num=1<<(lpBitmapInfoHeader->biBitCount/3);
			fTempBufforDisp*=num-1;
			fTempBufforDisp/=Diff;

			cur= y*biAlign+3*x;		//current pixel	
			m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
			m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
			/*
			m_pTransfered[cur]	= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
			*/
		}
	}
	}
	//显示图像的小波系数
	UpdateAllViews(NULL);
	//删除临时的数据空间
	delete spOriginData;
	delete spTransData0;
	delete spTransData1;
	return;	
}

void CWaveletDoc::OnWaveletThree() 
{
//读取数字图像的文件头,获取图像的属性参数
	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;
	if(m_pTransfered==NULL)
	{
		m_pTransfered=(unsigned char*) malloc (bmSize);
		m_pstore=new short [bmSize];
	}
	if(m_pTransfered==NULL)
		return;
	//图像矩阵坐标与像素数据
	int x,y,cur;
	unsigned char tempR, tempG, tempB;
	float fTempBufforDisp;
	short MaxPixVal,MinPixVal,Diff;
	short **spOriginData, **spTransData0, **spTransData1;
	//分配图像小波变换的数据内存空间
	spOriginData = new short* [biHeight];
	spTransData0 = new short* [biHeight];
	spTransData1 = new short* [biHeight];
	m_WaveletCoeff	= new short * [biHeight];
	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];
		spTransData1[i] = new short [biWidth];
		m_WaveletCoeff[i] = new short [biWidth];
	}
	//创建图像小波类
	CWaveletTrans *pTrans;
	//从设备的图像缓存中获取原始图像的数据
	for (i=0;i<=2;i++)
	{
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
            spOriginData[biHeight-1-y][x]=lpData[cur+i];
			/*
			tempB=lpData[cur];
			tempG=lpData[cur+1];
			tempR=lpData[cur+2];
			spOriginData[biHeight-1-y][x]=(short)(0.3*tempR+0.59*tempG+0.11*tempB);  //no problem
			*/
		}
	}
	//完成图像的三次小波变换
	pTrans->DWT_Three(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,3,1.414);
	//允许图像复员操作标志
	m_bOnce = FALSE;
	m_bTwice = FALSE;
	m_bTribl = TRUE;
	//m_bTribl = m_bTribl & ~m_bTwice & ~m_bOnce & ~m_bFilter;
	MaxPixVal=spTransData1[0][0];
	MinPixVal=spTransData1[0][0];
	//得到小波系数的极大值和极小值
	for( y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			if(MaxPixVal<spTransData1[y][x])
				MaxPixVal=spTransData1[y][x];
			if(MinPixVal>spTransData1[y][x])
				MinPixVal=spTransData1[y][x];
			//m_WvltCoeff[y][x] = spTransData1[y][x];
		}
	}
	//计算出小波系数的极值差
	Diff=MaxPixVal-MinPixVal;
	//将图像的小波数据处理后放入显示缓存中
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
		//因为小波变换后的小波系数有可能超过255甚至更多,那么就将
		//小波系数的范围映射到0~255区间内,以后出现类似的处理,目的都是一样的
			fTempBufforDisp=spTransData1[biHeight-1-y][x];
			fTempBufforDisp-=MinPixVal;
			long num;
			num=1<<(lpBitmapInfoHeader->biBitCount/3);
			fTempBufforDisp*=num-1;
			fTempBufforDisp/=Diff;

			cur= y*biAlign+3*x;		//current pixel	
			m_pstore[cur+i]=spTransData1[biHeight-1-y][x];
			m_pTransfered[cur+i]= (unsigned char)fTempBufforDisp;
			/*
			m_pTransfered[cur]	= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
			m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
			*/
		}
	}
	}
	
	//删除临时的数据空间
	delete spOriginData;
	delete spTransData0;
	delete spTransData1;


	//显示图像的小波变换
	UpdateAllViews(NULL);
	return;	
}

void CWaveletDoc::OnDwtNibianhuan() 
{
	// TODO: Add your command handler code here
	//读取数字图像的文件头,获取图像的属性参数

	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;

	if(m_pTransfered==NULL)
		m_pTransfered=(unsigned char*) malloc (bmSize);
	if(m_pTransfered==NULL)
		return;
	//图像矩阵的坐标
	int x,y,cur;
	//图像数据与图像处理数据的存放空间
	short **spOriginData, **spTransData0;
	spOriginData = new short* [biHeight];
	spTransData0 = new short* [biHeight];
	//分配数据的内存空间
	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];
	}
	//创建数字处理类
	CWaveletNibianhua *pDip;
	//如果图像只经过一次小波变换,则进行相应的逆变换
   
	for (i=0;i<=2;i++)
	{
		for(y=0; y<(int)biHeight; y++)
		{
			for(x=0; x<(int)biWidth; x++)
			{
				cur= y*biAlign+3*x;	
				m_WaveletCoeff[biHeight-1-y][x]=m_pstore[cur+i];
			}
		}

	if(m_bOnce)
	{
		pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff,biHeight,biHeight/2,biWidth,biWidth/2,1,1.414);
		if (i==2)
		  m_bOnce = FALSE;
	    //delete m_WvltCoeff;
	}
	//如果图像只经过两次小波变换,则进行相应的逆变换
	else if(m_bTwice)
	{
		pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff,biHeight ,biHeight/2,biWidth,biWidth/2,2,1.414);
		if (i==2)
			m_bTwice = FALSE;
		
	}
	//如果图像只经过三次小波变换,则进行相应的逆变换
	else if(m_bTribl)
	{
		pDip->FuYuan(spOriginData, spTransData0, m_WaveletCoeff, biHeight, biHeight/2,biWidth,biWidth/2,3,1.414);
		if (i==2)
			m_bTribl = FALSE;
		//delete m_WvltCoeff;
		
	}
	//判断是否有小波系数可以进行图像的复原
	else if(m_bFilter)
	{
		MessageBoxA(NULL,_T("没有找到可用小波系数,或者是未做小波变换"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
		m_bFilter = FALSE;
	}
	//将图像数据放入显示缓存中
	
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
			cur= y*biAlign+3*x;		//current pixel	
			m_pTransfered[cur+i]= (unsigned char)spOriginData[biHeight-1-y][x];
		}
	}

	}//for i
    delete m_WaveletCoeff;
	m_WaveletCoeff=NULL;
	//显示图像复原的结果
	UpdateAllViews(NULL);
	//删除临时的数据内存空间
	delete spOriginData;
	delete spTransData0;
}

void CWaveletDoc::OnCodeEzw() 
{
	// TODO: Add your command handler code here
	CEzwCode Ezw;
	int k=0;
	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);

	int biHeight = lpBitmapInfoHeader->biHeight;
	int biWidth = lpBitmapInfoHeader->biWidth;
	for (k=0;k<=2;k++)
		Ezw.EzwQualitition(minthr,biHeight,biWidth,k,m_pstore,&fsize);
	return;	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -