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

📄 testview.cpp

📁 方向自适应的小波变换程序(5/3) 本人自己编写
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		MyHeight=MyHeight<<(m-1);
		MyWidth=MyWidth<<(m-1);

		
	}
	for(i=0;i<lHeight;i++)
      for(j=0;j<lWidth;j++)
	  {
		  BYTE* lptemp=(BYTE*)lpDIBBits+(lHeight-i-1)*dwLineBytes+j;
		  (*lptemp)=(BYTE)origin[i][j];
	  }

	// 更新视图
	pDoc->UpdateAllViews(NULL);

/*  
	//将逆变换后的图像与原图像相比较,求出峰值信噪比
	//打开与解码文件对应的源位图文件
    char FiltersSource[]="*.bmp";
	CString PathName;
	CFile bmpSourceFile;
    CFileException fe;
	HDIB hDIBSource;
    LPSTR lpDIBSource;
	LPSTR lpSource,lptemp;

    CFileDialog dlgFileSource(TRUE,"bmp","*.bmp",OFN_READONLY,FiltersSource,this);
    if(dlgFileSource.DoModal ()==IDOK)
       PathName=dlgFileSource.GetPathName();
    else
	   return;
    bmpSourceFile.Open((LPCTSTR)PathName,CFile::modeRead,&fe);

    hDIBSource=::ReadDIBFile(bmpSourceFile);
	lpDIBSource=(LPSTR)::GlobalLock((HGLOBAL)hDIBSource);
    lpSource=FindDIBBits(lpDIBSource);
	double difference=0.0;
	lptemp=lpDIBBits;
	LPSTR lpSourcetemp=lpSource;

	for(i=0;i<::DIBHeight(lpDIB);i++)
		for(unsigned int j=0;j<::DIBWidth(lpDIB);j++)
	  { lptemp=lpDIBBits+i*(::DIBWidth(lpDIB))+j;
	    lpSourcetemp=lpSource+i*(::DIBWidth(lpDIB))+j;
		difference+=pow((double)((*lptemp)-(*lpSourcetemp)),double(2));
	  }

	double temp=255*255*(double)(::DIBWidth(lpDIB))*(double)(::DIBHeight(lpDIB));
	double ratio=10 * log10((double)(temp/difference));

	::GlobalUnlock (hDIBSource);
*/   

	// 解除锁定
	::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());	
	
}

void CTestView::quincunx_Prediction()
{
	int i,j,t1,t2,k;
	int E_dir=0;
	int **origin1;
	//保存原始图像副本
	origin1=new int* [MyHeight];
 	for(i=0;i<MyHeight;i++)
 	   origin1[i]=new int [MyWidth];
	for(i=0;i<MyHeight;i++)
		for(j=0;j<MyWidth;j++)
		{origin1[i][j]=origin[i][j];}
	//申请空间存储预测的方向
	Predict_direc=new int* [MyHeight/M];
 	for(i=0;i<MyHeight/M;i++)
 	   Predict_direc[i]=new int [MyWidth/N];
	//申请空间存储M*N快内的预测残差(h[m,n])的能量
	Block_energy=new int* [MyHeight/M];
 	for(i=0;i<MyHeight/M;i++)
 	   Block_energy[i]=new int [MyWidth/N];
	//初始化预测残差能量为最大
	for(i=0;i<MyHeight/M;i++)
		for(j=0;j<MyWidth/N;j++)
		{Block_energy[i][j]=100000;}
	
	int temp,temp1,temp2;
	int minEnergy_dir;
	int x[1],y[1],a,b;

	for(k=0;k<8;k++)
	{
		for(i=0;i<MyHeight;i++)
		{
			for(j=0;j<MyWidth;j++)
			{ 
				if((i+j)%2==1)
				{
					temp=origin[i][j];
					if(k!=2&&k!=6)
					{
						a=Predict_Direction[0][k];
						b=Predict_Direction[1][k];
						Bound_location(x,y,i,j,a,b);
						temp1=origin[*x][*y];
						
						Bound_location(x,y,i,j,-a,-b);
						temp2=origin[*x][*y];
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					else if(k==2)
					{
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					else if(k==6)
					{
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					
				}	
			}
		}
		for(i=0;i<MyHeight/M;i++)//计算某个方向下块内预测残差最小能量
		{
			for(j=0;j<MyWidth/N;j++)
			{
				minEnergy_dir=0;
				for(t1=0;t1<M;t1++)
					for(t2=0;t2<N;t2++)
					{		
						if((t1+t2)%2==1)
						{minEnergy_dir+=abs(origin[i*M+t1][j*N+t2]);}
					}
					if(minEnergy_dir<Block_energy[i][j])
					{
						Block_energy[i][j]=minEnergy_dir;
						Predict_direc[i][j]=k;
					}
			}
		}
		
		// 把原始像素值图像数组,继续预测
		for(i=0;i<MyHeight;i++)
			for(j=0;j<MyWidth;j++)
			{origin[i][j]=origin1[i][j];}
	}
//开始预测
	for(i=0;i<MyHeight;i++)
		{
			for(j=0;j<MyHeight;j++)
			{
				if((i+j)%2==1)
				{ 
					k=Predict_direc[(int)i/M][int(j/N)];
					temp=origin[i][j];
					if(k!=2&&k!=6)
					{
						a=Predict_Direction[0][k];
						b=Predict_Direction[1][k];
						
						Bound_location(x,y,i,j,a,b);
						temp1=origin[*x][*y];
						
						Bound_location(x,y,i,j,-a,-b);
						temp2=origin[*x][*y];
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					else if(k==2)
					{
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					else if(k==6)
					{
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					
				}	
			}
		}	

	 delete[] origin1;
	 origin1=NULL;

}

void CTestView::Bound_location(int *x, int *y, int i, int j, int a, int b)
{
	*x=i+a;
	*y=j+b;			
	if(*x<0)
		{*x=-*x;}
	if(*y<0)
		{*y=-*y;}
	if(*x>MyWidth-1)
		{*x=2*(MyWidth-1)-*x;}
	if(*y>MyHeight-1)
		{*y=2*(MyHeight-1)-*y;}
}

void CTestView::quincunx_Update()
{	
	int i,j,k;
	int temp,temp1,temp2;
	int x[1],y[1],a,b;
	
	for(i=0;i<MyHeight;i++)
		{
			for(j=0;j<MyWidth;j++)
			{
				if((i+j)%2==0)
				{ 
					k=Predict_direc[(int)i/M][int(j/N)];
					temp=origin[i][j];
					if(k!=2&&k!=6)
					{
						a=Predict_Direction[0][k];
						b=Predict_Direction[1][k];
						
						Bound_location(x,y,i,j,a,b);
						temp1=origin[*x][*y];
						
						Bound_location(x,y,i,j,-a,-b);
						temp2=origin[*x][*y];
						origin[i][j]=temp+(temp1+temp2)/4;
					}
					else if(k==2)
					{
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][5];
						b=Predict_Direction[1][5];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][7];
						b=Predict_Direction[1][7];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp+(temp1+temp2)/4;
					}
					else if(k==6)
					{
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,a,b);
						temp1=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,a,b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,-a,-b);
						temp1+=-origin[*x][*y];
						temp1=temp1/4;
						
						a=Predict_Direction[0][3];
						b=Predict_Direction[1][3];
						Bound_location(x,y,i,j,-a,-b);
						temp2=-origin[*x][*y];
						a=Predict_Direction[0][4];
						b=Predict_Direction[1][4];
						Bound_location(x,y,i,j,-a,-b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][0];
						b=Predict_Direction[1][0];
						Bound_location(x,y,i,j,a,b);
						temp2+=3*origin[*x][*y];
						a=Predict_Direction[0][1];
						b=Predict_Direction[1][1];
						Bound_location(x,y,i,j,a,b);
						temp2+=-origin[*x][*y];
						temp2=temp2/4;
						origin[i][j]=temp+(temp1+temp2)/4;
					}
					
				}	
			}
		}
//用于显示第一次预测和更新后的结果
/*	int *ttt;	
	ttt=new int[MyWidth];
	for(i=0;i<MyHeight;i++)
	{
		for(j=0;j<MyWidth;j++)
		{ttt[j]=origin[i][j];}
		for(j=0;j<MyWidth;j++)
		{
			if((i+j)%2==0)
			origin[i][j/2]=ttt[j];
			else
			origin[i][j/2+MyWidth/2]=ttt[j];
		}
	}
	delete[] ttt;
	 ttt=NULL;*/
}

void CTestView::quincunx_Prediction1()
{
	int i,j,t1,t2,k;
	int E_dir=0;
	int **origin1;
	//保存原始图像副本
	origin1=new int* [MyHeight];
 	for(i=0;i<MyHeight;i++)
 	   origin1[i]=new int [MyWidth];
	for(i=0;i<MyHeight;i++)
		for(j=0;j<MyWidth;j++)
		{origin1[i][j]=origin[i][j];}
	
	//申请空间存储预测的方向
	Predict_direc1=new int* [MyHeight/M];
 	for(i=0;i<MyHeight/M;i++)
 	   Predict_direc1[i]=new int [MyWidth/N];
	//申请空间存储M*N快内的预测残差(h[m,n])的能量
	Block_energy1=new int* [MyHeight/M];
 	for(i=0;i<MyHeight/M;i++)
 	   Block_energy1[i]=new int [MyWidth/N];
	for(i=0;i<MyHeight/M;i++)//初始化预测残差能量为最大
		for(j=0;j<MyWidth/N;j++)
		{Block_energy1[i][j]=100000;}
	
	int temp,temp1,temp2;
	int minEnergy_dir;
	int x[1],y[1],a,b;

	for(k=0;k<8;k++)
	{
		for(i=0;i<MyHeight;i++)
		{
			for(j=0;j<MyWidth;j++)
			{ 
				//if((i+j)%2==0 && i%2==0)+if((i+j)%2==1 && i%2==0)    =   i%2==0
				if((i+j)%2==0 && i%2==0)
				{
					temp=origin[i][j];
					if(k!=0&&k!=4)
					{
						a=Predict_Direction1[0][k];
						b=Predict_Direction1[1][k];
						
						Bound_location(x,y,i,j,a,b);
						temp1=origin[*x][*y];
						
						Bound_location(x,y,i,j,-a,-b);
						temp2=origin[*x][*y];
						origin[i][j]=temp-(temp1+temp2)/2;
					}
					else if(k==0)
		

⌨️ 快捷键说明

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