Rit*_*esh 5 matlab image image-processing feature-detection matlab-cvst
我正在研究指纹识别系统,并且已经完成了特征提取步骤。
我在两个图像之间有两组匹配点。我要做的是创建一个图像,以便两个图像并排显示。此图像应显示与线连接的匹配点:每条线的一端连接到第一幅图像中的匹配点,而线的另一端连接到第二幅图像中的相应匹配点。
提前致谢。
您可以使用showMatchedFeaturesMATLAB内置的函数。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功能。我不确定您有哪些工具箱。如果没有Computer Vision工具箱,则可以并排堆叠两个图像,然后在每对点之间循环运行并在它们之间画一条线。这是假设两个图像是相同的类型(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
Run Code Online (Sandbox Code Playgroud)
这应该大致实现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
Run Code Online (Sandbox Code Playgroud)