在图像处理中,镜像变换包括两种,关于Y轴镜像(即水平镜像)和关于X轴镜像(垂直镜像)
Y轴镜像(即水平镜像)就是在行不变的情况下,将图像的左右像素进行交换。以下代码适用于三通道图像。
代码如下:
void mirrorY(Mat src, Mat &dst)
{
int row=src.rows;
int col=src.cols;
dst=src.clone();
for (int i = 0; i < col; i++){
srcImage.col(col - 1 - i).copyTo(dst.col(i));
}
}
或者:
void mirrorY(Mat src, Mat &dst)
{
int row=src.rows;
int col=src.cols;
dst=src.clone();
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
dst.at<Vec3b>(i, j) = src.at<Vec3b>(i, col - 1 - j);
}
}
}
或者:
void mirrorY(Mat src, Mat &dst)
{
int row=src.rows;
int col=src.cols;