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

📄 wvltdoc.cpp

📁 一种新型小波树构造程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];
		spTransData1[i] = new short [biWidth];
		m_WvltCoeff[i] = new short [biWidth];
	}
	//创建图像小波变换类
	CWvltTrans *pTrans;
	//从设备缓存中获取原始图像数据
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			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_Once(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,1,1.414);
	//允许图像复原操作标志
	m_bOnce = TRUE;
	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;
			fTempBufforDisp*=255;
			fTempBufforDisp/=Diff;
			cur= y*biAlign+3*x;		//current pixel	
			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;
}

void CWvltDoc::OnWvltTransTwice() 
{
	// 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;
	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_WvltCoeff	= 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_WvltCoeff[i] = new short [biWidth];
	}
	//创建图像小波变化类
	CWvltTrans *pTrans;
	//从设备缓存中获取原始图像数据
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			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_TwoLayers(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,2,1.414);
	//允许图像复原操作标志
	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;
			fTempBufforDisp*=255;
			fTempBufforDisp/=Diff;
			cur= y*biAlign+3*x;		//current pixel	
			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;
}

void CWvltDoc::OnWvltTransTrbl() 
{
	// 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;
	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_WvltCoeff	= 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_WvltCoeff[i] = new short [biWidth];
	}
	//创建图像小波类
	CWvltTrans *pTrans;
	//从设备的图像缓存中获取原始图像的数据
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			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_TriLayers(spOriginData,spTransData0,spTransData1,biHeight,biHeight/2,biWidth,biWidth/2,3,1.414);
	//允许图像复员操作标志
	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;
			fTempBufforDisp*=255;
			fTempBufforDisp/=(float)Diff;
			cur= y*biAlign+3*x;		//current pixel	
			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;
}

void CWvltDoc::OnDiprocEnhace() 
{
	// 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;
	int tempR, tempG, tempB;
	//正则化小波系数的波动范围,NormWvltRng[0]存放极小值,NormWvltRng[1]存放极大值
	float NormWvltRng[2];
	//原始图像数据存储,数据用于图像对比度增强
	short **pData;
	//分配图像数据的内存空间
	pData = new short *[biHeight];
	for(int i = 0; i < biWidth; i++)
		pData[i] = new short [biWidth];
	//从设备缓存中获取原始图像的数据
	for(y = 0; y < biHeight; y ++)
	{
		for (x = 0; x < biWidth; x++)
		{
			cur = y * biAlign + 3 * x;
			tempB = lpData[cur];
			tempG = lpData[cur + 1];
			tempR = lpData[cur + 2];
			pData[biHeight - 1 - y][x] = 0.3 * tempR + 0.59 * tempG + 0.11 * tempB;
		}
	}
	//创建图像处理类
	CDiproc *pDIP;
	pDIP->DIP_ConsEnhance(pData, biHeight, biWidth, NormWvltRng);
	//将复原后的图像信息写入显示缓存中
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
			cur= y*biAlign+3*x;		//current pixel	
			m_pTransfered[cur]	= (unsigned char)pData[biHeight - 1- y][x];
 			m_pTransfered[cur+1]= (unsigned char)pData[biHeight - 1 - y][x];
			m_pTransfered[cur+2]= (unsigned char)pData[biHeight - 1 - y][x];
		}
	}
	//显示图像复原的结果
	UpdateAllViews(NULL);
	//删除临时的数据内存空间
	delete pData;

}

void CWvltDoc::OnDiprocFusion() 
{
	// 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;
	//定义图像的内存数据空间指针
	short **pData, **pDataFusion;
	CString cstrFileName = m_strFileFusion;
	//图像矩阵的坐标与像素数据
	int x, y, cur;
	int tempR, tempG, tempB;
	//分配图像的数据空间
	pData = new short * [biHeight];
	pDataFusion = new short * [biHeight];
	for(int i = 0; i < biWidth; i ++)
	{
		pDataFusion[i] = new short [biWidth];
		pData[i] = new short [biWidth];
	}
	//从设备的显示缓存中获取原始图像的数据
	for(y = 0; y < (int) biHeight; y ++)
	{
		for(x = 0; x < (int) biWidth; x ++)
		{
			cur = y * biAlign + 3 * x;
			tempB = lpData[cur];
			tempG = lpData[cur + 1];
			tempR = lpData[cur + 2];
			pData[biHeight - 1 - y][x] = 0.3 * tempR + 0.59 * tempG + 0.11 * tempB;
		}
	}
	//释放设备占用的显示缓存
	//m_pBitmap = NULL;
	//打开另外一幅用于融合的图像文件
	MessageBoxA(NULL,_T("请在WvltDip\\Fusion目录中打开另外一幅图像,进行图像融合"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
	while(!abs((int)strcmp(m_strFileFusion, cstrFileName)))
	{
		CFileDialog dlg( TRUE,NULL,NULL,
	                 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
	                 _T("Bitmap (*.BMP)|*.BMP|"));
		if( dlg.DoModal()==IDOK )
			cstrFileName = dlg.GetPathName();
		//如果文件重名,提示重新打开文件
		if(!abs((int)strcmp(m_strFileFusion, cstrFileName))) 
			MessageBoxA(NULL,_T("文件"+m_strFileFusion+"已打开,请打开该目录中另外一个文件"),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
		else
			MessageBoxA(NULL,_T("用于图像融合的文件是:\n"+m_strFileFusion+"\n"+cstrFileName),_T("Message"),MB_ICONEXCLAMATION|MB_OK);
	}
	//读取位图数据,载入显示缓存中
	ReadBitmap(cstrFileName, m_pTransfered);
	//显示新打开的图像
	UpdateAllViews(NULL);
	//读取另外一幅图像的数据
	lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pTransfered+14);
	lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pTransfered;
	unsigned char *lpImgData = m_pTransfered + lpBitmapFileHeader->bfOffBits;

⌨️ 快捷键说明

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