我正在研究指纹识别系统,并完成了特征提取的步骤。
我在两张图片之间有两组匹配点。我想要做的是创建一个图像,以便两个图像并排显示。此图像应显示与线条相关的匹配点:每条线的一端连接到第一个图像中的匹配点,线的另一端连接到第二个图像中的相应匹配点。
提前致谢。
答案 0 :(得分:4)
您可以使用MATLAB内置的showMatchedFeatures
函数。如果您使用了任何内置特征检测算法,或者两个大小为features
的矩阵,则该函数可以采用一对N x 2
结构。其中两个是必需的,因为每个都描述了两个图像之间的哪些坐标对彼此对应。该功能还需要您检测到关键点的两个图像。
你可以用一些透明度来呈现它们,或者最流行的方法是将它们彼此并排放置,并在每对相应点之间绘制一条线(我相信这是你之后的事情)
查看MATLAB文档以获取更多详细信息:
http://www.mathworks.com/help/vision/ref/showmatchedfeatures.html
如果您想查看一些示例代码和输出,请点击此处:
http://www.mathworks.com/help/vision/ref/showmatchedfeatures.html#btfmijs
NB:您需要使用计算机视觉工具箱才能运行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
答案 1 :(得分:1)
我个人需要使用彩色图像,所以我想我会通过rayryeng发布不同大小但适合彩色图像实现的图像的代码(注意点现在是行xy格式而不是列xy格式)
figure;
[rows1,cols1] = size(im1(:,:,1));
[rows2,cols2] = size(im2(:,:,1));
%// Create blank image
stackedImage = uint8(zeros(max([rows1,rows2]), cols1+cols2,3));
%// 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(:,:,1), 2);
hold on;
numPoints = size(points1, 2); % points2 must have same # of points
% Note, we must offset by the width of the image
for i = 1 : numPoints
plot(points1(1, i), points1(2, i), 'b*', points2(1, i) + width, ...
points2(2, i), 'r*');
line([points1(1, i) points2(1, i) + width], [points1(2, i) points2(2, i)], ...
'Color', 'green');
end