📄 testview.cpp
字号:
sum1+= origin[x][i]*Sinc_interpolation[0][l+M_sample-1];
//sum2+= origin[x][i]*sin(PI*(0.5-l))/(PI*(0.5-l));
sum2+= origin[x][i]*Sinc_interpolation[1][l+M_sample-1];
//sum3+= origin[x][i]*sin(PI*(0.75-l))/(PI*(0.75-l));
sum3+= origin[x][i]*Sinc_interpolation[2][l+M_sample-1];
}
ori_QuartPixel_interp1[4*j+1][i]=int(sum1);
ori_QuartPixel_interp1[4*j+2][i]=int(sum2);
ori_QuartPixel_interp1[4*j+3][i]=int(sum3);
sum1=sum2=sum3=0;
}
}
void CTestView::Horizontal_Direction_Prediction()
{
int i,j,t1,t2,k;
int E_dir=0;
//申请空间存储预测的方向
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,y;
int Dir=4;//0->传统提升,4->方向提升
for(k=-Dir;k<=Dir;k++)
{// 先行后列
for(j=0;j<MyWidth;j++)//前MyHeight-1行
{
for(i=1;i<MyHeight-1;i+=2)
{
temp=ori_QuartPixel_interp[i][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[i-1][x];
temp2=ori_QuartPixel_interp[i+1][y];
ori_QuartPixel_interp[i][4*j]=temp-(temp1+temp2)/2;
}
}
for(j=0;j<MyWidth;j++) //第MyHeight-1行
{
temp=ori_QuartPixel_interp[MyHeight-1][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[MyHeight-2][x];
temp2=ori_QuartPixel_interp[MyHeight-2][y];
ori_QuartPixel_interp[MyHeight-1][4*j]=temp-(temp1+temp2)/2;
}
for(i=0;i<MyHeight/M;i++)//计算某个方向下块内预测残差最小能量
{
for(j=0;j<MyWidth/N;j++)
{
minEnergy_dir=0;
for(t1=1;t1<M;t1+=2)
for(t2=0;t2<N;t2++)
{
minEnergy_dir+=abs(ori_QuartPixel_interp[i*M+t1][j*N*4+t2*4]);
}
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++)
{ ori_QuartPixel_interp[i][j*4] = origin[i][j];}
}
for(j=0;j<MyWidth;j++)
{
for(i=1;i<MyHeight-1;i+=2)//前MyHeight-1行
{
k=Predict_direc[(int)i/M][int(j/N)];
temp=ori_QuartPixel_interp[i][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[i-1][x];
temp2=ori_QuartPixel_interp[i+1][y];
ori_QuartPixel_interp[i][4*j]=temp-(temp1+temp2)/2;
}
}
for(j=0;j<MyWidth;j++) //第MyHeight-1行
{
k=Predict_direc[MyHeight/M-1][int(j/N)];
temp=ori_QuartPixel_interp[MyHeight-1][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[MyHeight-2][x];
temp2=ori_QuartPixel_interp[MyHeight-2][y];
ori_QuartPixel_interp[MyHeight-1][4*j]=temp-(temp1+temp2)/2;
}
for(i=0;i<MyHeight;i++)
for(j=0;j<MyWidth;j++)
{origin[i][j]=ori_QuartPixel_interp[i][4*j];}
}
void CTestView::Vertical_Direction_Prediction()
{
int i,j,t1,t2,k;
int E_dir=0;
//申请空间存储预测的方向
Predict_direc1=new int* [MyHeight/M];
for(i=0;i<MyHeight/M;i++)
Predict_direc1[i]=new int [MyWidth/N];
//申请空间存储16*16快内的预测残差(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,y;
int Dir=4;//0->传统提升,4->方向提升
for(k=-Dir;k<=Dir;k++)
{
for(i=0;i<MyHeight;i++)
{
for(j=1;j<MyWidth-1;j+=2)//前MyWidth-1列
{
temp=ori_QuartPixel_interp1[4*i][j];
x=4*i+k;
y=4*i-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][j-1];
temp2=ori_QuartPixel_interp1[y][j+1];
ori_QuartPixel_interp1[i*4][j]=temp-(temp1+temp2)/2;
}
}
for(j=0;j<MyHeight;j++) //第MyWidth-1列
{
temp=ori_QuartPixel_interp1[4*j][MyWidth-1];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][MyWidth-2];
temp2=ori_QuartPixel_interp1[y][MyWidth-2];
ori_QuartPixel_interp1[4*j][MyWidth-1]=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=1;t2<N;t2+=2)
{
minEnergy_dir+=abs(ori_QuartPixel_interp1[i*M*4+t1*4][j*N+t2]);
}
if(minEnergy_dir<Block_energy1[i][j])
{
Block_energy1[i][j]=minEnergy_dir;
Predict_direc1[i][j]=k;
}
}
}
// 把原始像素值写回插值后的数组,继续预测
for(i=0;i<MyHeight;i++)
for(j=0;j<MyWidth;j++)
{ ori_QuartPixel_interp1[4*i][j] = origin[i][j];}
}
for(j=1;j<MyWidth-1;j+=2)//前MyWidth-1列
{
for(i=0;i<MyHeight;i++)
{
k=Predict_direc1[(int)i/M][int(j/N)];
temp=ori_QuartPixel_interp1[4*i][j];
x=4*i+k;
y=4*i-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][j-1];
temp2=ori_QuartPixel_interp1[y][j+1];
ori_QuartPixel_interp1[4*i][j]=temp-(temp1+temp2)/2;
}
}
for(j=0;j<MyHeight;j++) //第MyWidth-1列
{
k=Predict_direc1[int(j/M)][MyWidth/N-1];
temp=ori_QuartPixel_interp1[4*j][MyWidth-1];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][MyWidth-2];
temp2=ori_QuartPixel_interp1[y][MyWidth-2];
ori_QuartPixel_interp1[4*j][MyWidth-1]=temp-(temp1+temp2)/2;
}
for(i=0;i<MyHeight;i++)
for(j=0;j<MyWidth;j++)
{origin[i][j]=ori_QuartPixel_interp1[4*i][j];}
}
void CTestView::Horizontal_Update()
{
int i,j,k;
int temp,temp1,temp2;
int x,y;
for(j=0;j<MyWidth;j++) //第1行更新
{
k=Predict_direc[0][int(j/N)];
temp=ori_QuartPixel_interp[0][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[1][x];
temp2=ori_QuartPixel_interp[1][y];
ori_QuartPixel_interp[0][4*j]=temp+(temp1+temp2)/4;
}
for(j=0;j<MyWidth;j++)//后MyHeight-1行
{
for(i=2;i<MyHeight;i+=2)
{
k=Predict_direc[(int)i/M][int(j/N)];
temp=ori_QuartPixel_interp[i][4*j];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyWidth-1)
{x=8*(MyWidth-1)-x;}
if(y>4*MyWidth-1)
{y=8*(MyWidth-1)-y;}
temp1=ori_QuartPixel_interp[i-1][x];
temp2=ori_QuartPixel_interp[i+1][y];
ori_QuartPixel_interp[i][4*j]=temp+(temp1+temp2)/4;
}
}
for(i=0;i<MyHeight/2;i++)
for(j=0;j<MyWidth;j++)
{
origin[i][j]=ori_QuartPixel_interp[2*i][4*j];
origin[i+MyHeight/2][j]=ori_QuartPixel_interp[2*i+1][4*j];
}
}
void CTestView::Vertical_Update()
{
int i,j,k;
int temp,temp1,temp2;
int x,y;
for(j=0;j<MyHeight;j++) //第1列更新
{
k=Predict_direc1[int(j/M)][0];
temp=ori_QuartPixel_interp1[4*j][0];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][1];
temp2=ori_QuartPixel_interp1[y][1];
ori_QuartPixel_interp1[4*j][0]=temp+(temp1+temp2)/4;
}
for(j=0;j<MyHeight;j++)//后MyWidth-1列
{
for(i=2;i<MyWidth;i+=2)
{
k=Predict_direc1[(int)j/M][int(i/N)];
temp=ori_QuartPixel_interp1[4*j][i];
x=4*j+k;
y=4*j-k;
if(x<0)
{x=-x;}
if(y<0)
{y=-y;}
if(x>4*MyHeight-1)
{x=8*(MyHeight-1)-x;}
if(y>4*MyHeight-1)
{y=8*(MyHeight-1)-y;}
temp1=ori_QuartPixel_interp1[x][i-1];
temp2=ori_QuartPixel_interp1[y][i+1];
ori_QuartPixel_interp1[4*j][i]=temp+(temp1+temp2)/4;
}
}
for(i=0;i<MyHeight;i++)
for(j=0;j<MyWidth/2;j++)
{
origin[i][j]=ori_QuartPixel_interp1[4*i][2*j];
origin[i][j+MyWidth/2]=ori_QuartPixel_interp1[4*i][2*j+1];
}
}
void CTestView::OnIntAdlWaveletBackward()
{
// 获取文档
CTestDoc* pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
// 指向DIB象素指针
LPSTR lpDIBBits;
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
// 找到DIB图像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图,其它的可以类推)
if (::DIBNumColors(lpDIB) != 256)
{
// 提示用户
MessageBox("目前只支持查看256色位图灰度直方图!", "系统提示" , MB_ICONINFORMATION | MB_OK);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
// 返回
return;
}
int lHeight,lWidth;
int i,j,m;
lHeight=::DIBHeight(lpDIB);
lWidth=::DIBWidth(lpDIB);
DWORD dwLineBytes=WIDTHBYTES(lWidth*8);
MyHeight=lHeight;
MyWidth=lWidth;
/* 这么做不可以,这样得到的origin 数据不正确
int **origin=new int* [lHeight];
for(DWORD i=0;i<lHeight;i++)
origin[i]=new int [lWidth];
for(i=0;i<lHeight;i++)
for(DWORD j=0;j<lWidth;j++)
{
LPSTR lptemp=lpDIBBits+(lHeight-i-1)*dwLineBytes+j;
origin[i][j]=(int)(*lptemp);
} */
// inverse_wavelet_transform_overlap(origin,lWidth,lHeight,3);
for(m=levels;m>0;m--)
{
MyHeight=MyHeight>>(m-1);
MyWidth=MyWidth>>(m-1);
//行变换
Vertical_Sinc_interpolation();//插值
inverse_Vertical_Update(m);// 逆更新
Vertical_Sinc_interpolation();//插值
inverse_Vertical_Prediction(m);//逆预测
//列变换
Horizontal_Sinc_interpolation();//插值
inverse_Horizontal_Update(m);//逆更新
Horizontal_Sinc_interpolation();//插值
inverse_Horizontal_Prediction(m);//逆预测
//ADLwavelet_transform_overlap(origin,dwLineBytes,lHeight,3);
//下一级逆变换初始化
MyHeight=MyHeight<<(m-1);
MyWidth=MyWidth<<(m-1);
if(ori_QuartPixel_interp!=NULL)
{delete ori_QuartPixel_interp;
ori_QuartPixel_interp=NULL;}
if(ori_QuartPixel_interp1!=NULL)
{delete ori_QuartPixel_interp1;
ori_QuartPixel_interp1=NULL;}
}
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));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -