【发布时间】:2014-05-09 03:55:31
【问题描述】:
我正在开发一个指纹识别系统,并且已经完成了特征提取的步骤。
我在两个图像之间有两组匹配点。我想要做的是创建一个图像,以便两个图像并排显示。此图像应显示与线连接的匹配点:每条线的一端连接到第一张图像中的匹配点,线的另一端连接到第二张图像中的对应匹配点。
提前致谢。
【问题讨论】:
标签: image matlab image-processing feature-detection matlab-cvst
我正在开发一个指纹识别系统,并且已经完成了特征提取的步骤。
我在两个图像之间有两组匹配点。我想要做的是创建一个图像,以便两个图像并排显示。此图像应显示与线连接的匹配点:每条线的一端连接到第一张图像中的匹配点,线的另一端连接到第二张图像中的对应匹配点。
提前致谢。
【问题讨论】:
标签: image matlab image-processing feature-detection matlab-cvst
您可以使用 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
注意:您需要计算机视觉工具箱才能运行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
【讨论】:
我个人需要使用彩色图像,所以我想我会为不同尺寸的图像发布代码,但适用于彩色图像实现(请注意,点现在是 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
【讨论】: