|
数学表达式原理:
设图像高度为IHeight,宽度为IWidth,原图中(x0,y0)经过水平镜像后从未将变为
(IWidth-x0,y0),其表达式为:
X0=IWidth-y1; y0=y1
算法的C语言代码:
/*水平镜像变换处理*/
void horizTranspose()
{
int i,j;
for(i=0;i
{
/*前半部分为原始图像*/
//传送临时Y缓冲区
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempYbuffer + i * numPixels),
numPixels>>1);
//传送临时Cb缓冲区
DAT_copy((void *)(capCbbuffer + i * (numPixels >> 1)),
(void *)(tempCbbuffer + i * (numPixels >> 1)),
numPixels>>2);
//传送临时Cr缓冲区
DAT_copy((void *)(capCrbuffer + i * (numPixels >> 1)),
(void *)(tempCrbuffer + i * (numPixels >> 1)),
numPixels>>2);
/*后半部分为水平镜像图像*/
for(j=numPixels/2;j
{
//传送临时Y缓冲区
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(capYbuffer + i*numPixels + numPixels-1-j);
}
for(j=(numPixels>>2);j<(numPixels>>1);j++)
{
//传送临时Cb缓冲区
*(Uint8 *)(tempCbbuffer + i*(numPixels>>1) + j) = *(Uint8 *)(capCbbuffer + i*(numPixels>>1) + (numPixels>>1)-1-j);
//传送临时Cr缓冲区
*(Uint8 *)(tempCrbuffer + i*(numPixels>>1) + j) = *(Uint8 *)(capCrbuffer + i*(numPixels>>1) + (numPixels>>1)-1-j);
}
}
}
四、图像的缩放算法
数学表达式原理:
假设图像x轴方向缩放比率fx,y轴方向缩放比率是fy,那么原图中点(x0,y0)对应
于新图中的点(x1,y1)的转换表达式为:
X0=x1/fx; y0=y1/fy
算法的C语言代码:
/*图像缩放参数*/
Float fXZoomRatio=0.5; //水平缩放比率
Float fYZoomRatio=0.5; //垂直缩放比率
/*缩放处理函数*/
/*缩放处理*/
void zoom()
{
int i,j;
int intCapX,intCapY;
for(i=0;i
{
for(j=0;j
{
intCapX = (int)(j/fYZoomRatio+0.5);
intCapY = (int)(i/fXZoomRatio+0.5);
//判断是否在原图范围内
if((intCapX>=0) && (intCapX
{
if((i=0) && (intCapY
{
//传送亮度信号
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(capYbuffer + intCapY*numPixels + intCapX);
}
else if((i>=numLines/2) && (i=numLines/2) && (intCapY
{
//传送亮度信号
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(capYbuffer + intCapY*numPixels + intCapX);
}
else
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0xFF;
}
}
else
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0xFF;
}
}
}
}
|
|