配准之棋盘网格图(镶嵌图像)(附有 C++ 代码)

        在查阅了大量的资料后,虽然也找到了一些有关图像配准的精度评价指标,如:特征点检测评价、假定匹配率、召回率、精确率(均已用C++实现,参考:遥感影像评价指标的实现)等;但其中大部分仅仅适用于常规图像、单时相影像配准的评价,在应用于多时相影像配准的精度评价时,往往参考意义不大;经过一番考虑后打算使用棋盘网格图对遥感影像配准结果可视化显示。

/********************该函数生成两幅图的棋盘网格图*************************/
/*image_1表示参考图像
  image_2表示配准后的待配准图像
  chessboard_1表示image_1的棋盘图像
  chessboard_2表示image_2的棋盘图像
  mosaic_image表示image_1和image_2的镶嵌图像
  width表示棋盘网格大小
 */
void mosaic_map(const Mat& image_1, const Mat& image_2, Mat& chessboard_1, Mat& chessboard_2, Mat& mosaic_image, int width)
{
	if (image_1.size != image_2.size)
		CV_Error(CV_StsBadArg, "mosaic_map模块输入两幅图大小必须一致!");

	//生成image_1的棋盘网格图
	chessboard_1 = image_1.clone();

	int rows_1 = chessboard_1.rows;
	int cols_1 = chessboard_1.cols;

	int row_grids_1 = cvFloor((double)rows_1 / width);		//行方向网格个数
	int col_grids_1 = cvFloor((double)cols_1 / width);		//列方向网格个数

	//指定区域像素赋值为零,便形成了棋盘图

	//第一幅图,第一行 2、4、6 像素值赋值零;第一幅图与第二幅图零像素位置交叉,以便两幅图交叉显示
	for (int i = 0; i < row_grids_1; i = i + 2) 
	{
		for (int j = 1; j < col_grids_1; j = j + 2)		
		{
			Range range_x(j * width, (j + 1) * width);
			Range range_y(i * width, (i + 1) * width);

			chessboard_1(range_y, range_x) = 0;
		}
	}

	for (int i = 1; i < row_grids_1; i = i + 2) 
	{
		for (int j = 0; j < col_grids_1; j = j + 2)		
		{
			Range range_x(j * width, (j + 1) * width);
			Range range_y(i * width, (i + 1) * width);

			chessboard_1(range_y, range_x) = 0;
		}
	}

	//生成image_2的棋盘网格图

	chessboard_2 = image_2.clone();

	int rows_2 = chessboard_2.rows;
	int cols_2 = chessboard_2.cols;

	int row_grids_2 = cvFloor((double)rows_2 / width);//行方向网格个数
	int col_grids_2 = cvFloor((double)cols_2 / width);//列方向网格个数

	//第二幅图,第一行 1、3、5 像素值赋值零
	for (int i = 0; i < row_grids_2; i = i + 2) 
	{
		for (int j = 0; j < col_grids_2; j = j + 2) 
		{
			Range range_x(j * width, (j + 1) * width);
			Range range_y(i * width, (i + 1) * width);
			chessboard_2(range_y, range_x) = 0;
		}
	}

	for (int i = 1; i < row_grids_2; i = i + 2) 
	{
		for (int j = 1; j < col_grids_2; j = j + 2) 
		{
			Range range_x(j * width, (j + 1) * width);
			Range range_y(i * width, (i + 1) * width);
			chessboard_2(range_y, range_x) = 0;
		}
	}

	//两个棋盘图进行叠加,显示配准效果
	mosaic_image = chessboard_1 + chessboard_2;
}


int main()
{
	//生成棋盘网格图像
	Mat chessboard_1, chessboard_2, mosaic_images;

	Mat image1 = imread("1.jpg", -1);
	Mat image2 = imread("2.jpg", -1);

	mosaic_map(image1, image2, chessboard_1, chessboard_2, mosaic_images, 100);

	imwrite("D:\11.jpg", chessboard_1);        //第一幅图的网格棋盘图
	imwrite("D:\22.jpg", chessboard_2);        //第二幅图的网格棋盘图
	imwrite("D:\33.jpg", mosaic_images);       //两幅网格棋盘图的叠加结果

    return 0;
}

输出结果:

图1 第一幅图网格棋盘图

 图2 第二幅图网格棋盘图

图3 两幅图网格棋盘图叠加结果

 说明:如果两幅网格棋盘图叠加结果显示,第一幅图和第二幅图中的同名点部分能够很好的对应上,则说明配准结果良好;

注:输入的两幅图要求尺寸一样,原则上如果两幅图配准结果较好,则两幅图网格棋盘图叠加结果刚好是一幅完整的图(和图一或图二相差无几),由于相关数据无法泄露,随便在网上找了两幅图,从结果可以看出,这两幅图用在此处显然效果不是很友好;

猜你喜欢

转载自blog.csdn.net/weixin_47156401/article/details/120186457
今日推荐