图像的旋转实验DSP6000
数学表达式原理:
下面我们来推导一下旋转运算的变换公式。如下图所示,点(x0,y0)经过旋转θ度后
坐标变成(x1,y1)。其数学表达式为:
X0=x1cos(θ)+y1sin(θ)+ccos(θ)-dsin(θ)+a ;
Y0=-xsin(θ)+y1cos(θ)+csin(θ)-dcos(θ)+ b
算法的C语言代码:
/*图像旋转参数*/
Float fAngle=3.1415927/3; //旋转的角度
*画矩形边框函数*/
Void drawRectangle();
*计算图像旋转参数*/
Void computeParameter();
/*进行图像旋转处理*/
void rotate()
{
int i,j,intInc;
int intCapYInc;
int intCapX,intCapY;
/*进行图像旋转,重新赋值*/
//方框内奇数行
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intInc = i*2;
intCapX = (int)(j*cosAngle + intInc*sinAngle + f1 + 0.5);
intCapYInc = (int)(intInc*cosAngle - j*sinAngle + f1 + 0.5);
if((intCapYInc%2)==0)
{
intCapY = intCapYInc/2;
}
else
{
intCapY = (intCapYInc-1)/2+numLines/2;
}
//判断是否在原图范围内
if((intCapX>=0) && (intCapX<numPixels) && (intCapY>=0) && (intCapY<numLines))
{
//传送亮度信号
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(capYbuffer + intCapY*numPixels + intCapX);
}
else
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0xFF;
}
}
}
//方框内偶数行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
intInc = (i-numLines/2)*2 + 1;
intCapX = (int)(j*cosAngle + intInc*sinAngle + f1 + 0.5);
intCapYInc = (int)(intInc*cosAngle - j*sinAngle + f1 + 0.5);
if((intCapYInc%2)==0)
{
intCapY = intCapYInc/2;
}
else
{
intCapY = (intCapYInc-1)/2+numLines/2;
}
//判断是否在原图范围内
if((intCapX>=0) && (intCapX<numPixels) && (intCapY>=0) && (intCapY<numLines))
{
//传送亮度信号
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(capYbuffer + intCapY*numPixels + intCapX);
}
else
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0xFF;
}
}
}
} |