对于图像边缘锯齿的处理想法是对图像的边缘使用高斯平滑处理去除锯齿,对于图像的其他非边缘则保持不变。
至于找图像边缘,如果知道图像边缘的映射方式,可以直接用变换公式处理;不知道映射方式的情况下,通常选用Canny算子提取边缘。
1 . 对于旋转图像时产生的边缘图像锯齿处理(知道边缘的映射方式)
void rotateImg(CvMat* src, CvMat* dst, double angle)
{
double tempX = 0.0;
double tempY = 0.0;
angle = 3.14 * angle/180.0;
for(int y = 0; y < dst->height; y++)
{
for(int x = 0; x < dst->width; x++)
{
tempY = src->height/2 + (y - src->height/2)*cos(angle) + (x - src->width/2) *sin(angle);
tempX = src->width/2 - (y - src->height/2)*sin(angle) + (x - src->width/2) *cos(angle);
if(tempX >= 0 && tempX < src->width && tempY >=0 && tempY < src->height)
{
*(dst->data.ptr + y * dst->width + x) = saturate_cast<uchar>(cvmGet(src,tempY,tempX));
}else
{
*(dst->data.ptr + y * dst->width + x) = 0;
}
}
}
} // 旋转变换
void getedgeimg(IplImage *src, IplImage *dst)
{
for(int idx = 0 ; idx < src->width;idx++)
{
for(int idy = 0; idy < src->height;idy++)
{
if(idx <= 0 || idy <= 0 || idx >= src->width -1 || idy >= src->width -1)
{
CV_IMAGE_ELEM(dst,uchar,idy,idx) = CV_IMAGE_ELEM(src,uchar,idy,idx);
}