大家帮忙看看这是什么插值,它是利用权值来更新相邻四个点的灰度,是不是PV插值的另外一种表现形式
void CCxy1Doc::greychaz()
{
int i,j;
for(i=0;i <m_dibsize2.cx;i++)
{
for(j=0;j <m_dibsize2.cy;j++)
{
imagechang[i+j*m_dibsize2.cx]=0;
}
}
int i0,j0;
/////////////////
//计算变换后的坐标及对应的灰度值
for(i=0;i <m_dibsize2.cx;i++)
{
for(j=0;j <m_dibsize2.cy;j++)
{
double temp1,temp2;
double orginx=(m_dibsize2.cx-1)/2.0;//中心点(x,y)
double orginy=(m_dibsize2.cy-1)/2.0;
//引用了书上的,B到B'的变换公式,temp1为横坐标,temp2为纵坐标
temp1=m_extend*(orginx+sin(m_rotation)*(orginy-j)-cos(m_rotation)*(orginx-i)+m_displacex-orginx)+orginx; //geometric transformation
temp2=m_extend*(orginy-cos(m_rotation)*(orginy-j)-sin(m_rotation)*(orginx-i)+m_displacey-orginy)+orginy;
if(temp1>=0) /*(temp1,temp2)取整为(i0,j0)*/
i0 = (int)(temp1 + 0.5);
if(temp1 <0)
i0= (int)(temp1-0.5);
if(temp2>0)
j0 = (int)(temp2+0.5);
if(temp2 <=0)
j0 = (int)(temp2 - 0.5);
changx[i+j*tt]=i0;
changy[i+j*tt]=j0;
int x1=int(temp1);
int y1=int(temp2);
int x2=x1+1;
int y2=y1+1;
if((x2 <300)&&(x1>0)&&(y2 <300)&&(y1>0))
{
double mx,my,dx,dy,d1,d2,d3,d4,px,py;
mx=modf(temp1,&px);
my=modf(temp2,&py);
if((mx!=0)||(my!=0))
{
//determin the weoghts
dx=temp1-x1;
dy=temp2-y1;
d1=(1-dx)*(1-dy);
d2=dx*(1-dy);
d3=dx*dy;
d4=(1-dx)*dy;
//count the histogram
int gre;
gre=dib2.m_lpImage[i+j*m_dibsize2.cx];
imagechang[x1+y1*m_dibsize2.cx]+=gre*d1;
imagechang[x2+y1*m_dibsize2.cx]+=gre*d2;
imagechang[x2+y2*m_dibsize2.cx]+=gre*d3;
imagechang[x1+y2*m_dibsize2.cx]+=gre*d4;
}
else
imagechang[int(temp1)+int(temp2)*m_dibsize2.cx]+=dib2.m_lpImage[i+j*m_dibsize2.cx];
}
}
}
}