您可以使用MATLAB内置的showMatchedFeatures函数.如果您使用了任何内置特征检测算法,或者两个大小为N x 2的矩阵,该函数可以采用一对特征结构.其中两个是必需的,因为每个都描述了两个特征之间的坐标对.两个图像彼此对应.该功能还需要您检测到关键点的两个图像.

您可以使用一些透明度来呈现它们,或者最流行的方法是将它们彼此并排放置,并在每对相应点之间绘制一条线(我相信这就是您所追求的).

查看MATLAB文档以获取更多详细信息:

如果您想查看一些示例代码和输出,请在此处查看:

另外一个选项

注意:您需要计算机视觉工具箱才能运行showMatchedFeatures功能.我不确定你有哪些工具箱.如果您没有计算机视觉工具箱,那么您可以并排堆叠两个图像,然后在每对点中运行一个循环并在它们之间画一条线.这假设两个图像都是相同类型(uint8,uint16等)并且都是灰度图像.

假设您有图像处理工具箱,您可以这样做:

% Assuming im1 and im2 are already loaded into your environment

% im1 and im2 are the two images you are comparing to

% points1 and points2 are M x 2 matrices of corresponding points

% between im1 and im2

% The co-ordinates in the ith row of points1 correspond to the

% ith row of points2

% Important Note: Each row assumes co-ordinates in (x,y) format

% x - horizontal, y - vertical

% y is assumed to be y-down (i.e. downwards is positive)

figure;

stackedImage = cat(2, im1, im2); % Places the two images side by side

imshow(stackedImage);

width = size(im1, 2);

hold on;

numPoints = size(points1, 1); % points2 must have same # of points

% Note, we must offset by the width of the image

for i = 1 : numPoints

plot(points1(i, 1), points1(i, 2), 'y+', points2(i, 1) + width, ...

points2(i, 2), 'y+');

line([points1(i, 1) points2(i, 1) + width], [points1(i, 2) points2(i, 2)], ...

'Color', 'yellow');

end

这应该大致实现showMatchedFeatures的功能.

如果两个图像的尺寸不同,会怎么样?

如果您想要比较的两个图像都没有相同的尺寸(即两个图像不共享相同数量的行和/或列),您只需创建一个首先为空白的输出图像,输出的总行数是两者之间的行的最大值,列总数是它们的总和.因此,您只需这样做.这假设两个图像都是相同的类型,并且像之前一样是灰度:

figure;

[rows1,cols1] = size(im1);

[rows2,cols2] = size(im2);

%// Create blank image

stackedImage = zeros(max([rows1,rows2]), cols1+cols2);

stackedImage = cast(stackedImage, class(im1)); %// Make sure we cast output

%// Place two images side by side

stackedImage(1:rows1,1:cols1) = im1;

stackedImage(1:rows2,cols1+1:cols1+cols2) = im2;

%// Code from before

imshow(stackedImage);

width = size(im1, 2);

hold on;

numPoints = size(points1, 1); % points2 must have same # of points

% Note, we must offset by the width of the image

for i = 1 : numPoints

plot(points1(i, 1), points1(i, 2), 'y+', points2(i, 1) + width, ...

points2(i, 2), 'y+');

line([points1(i, 1) points2(i, 1) + width], [points1(i, 2) points2(i, 2)], ...

'Color', 'yellow');

end

更多推荐