【问题标题】:Draw matched points between two images in MATLAB在 MATLAB 中绘制两个图像之间的匹配点
【发布时间】:2014-05-09 03:55:31
【问题描述】:

我正在开发一个指纹识别系统,并且已经完成了特征提取的步骤。

我在两个图像之间有两组匹配点。我想要做的是创建一个图像,以便两个图像并排显示。此图像应显示与线连接的匹配点:每条线的一端连接到第一张图像中的匹配点,线的另一端连接到第二张图像中的对应匹配点。

提前致谢。

【问题讨论】:

    标签: image matlab image-processing feature-detection matlab-cvst


    【解决方案1】:

    您可以使用 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 函数。我不确定您有哪些工具箱可用。如果您没有计算机视觉工具箱,那么您可以并排堆叠两个图像,然后通过每对点运行一个循环并在它们之间画一条线。这是假设两个图像是同一类型uint8uint16 等)并且都是灰度

    假设您有可用的图像处理工具箱,您可以执行以下操作:

    % 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
    

    【讨论】:

    • 非常感谢 rayryeng...这就是我一直在寻找的东西...我确实有一个计算机视觉工具箱 2012a 但没有“showMatchedFeature”功能...在使用您的绘图线时代码中,线条绘制在同一图像中,即 image1...what to do..
    • 您好。这就是不测试我的代码的症结所在。我修好了它。检查上面的新代码。基本上我忘记做的是将第二张图像中匹配特征的 x 坐标偏移宽度。坐标假设您正在找到与任一图像尺寸相关的匹配坐标。如果要显示堆叠在一起的图像之间的匹配,则需要将第二张图像中匹配点的 x 坐标偏移宽度。刚刚运行了一个测试,它的工作原理。告诉我。
    • 这不是一个错误,而只是一个错误..我已经纠正了它..您更新的代码很好并且可以工作..在偏移 x 坐标的过程中,我取了错误的值。 .所以线条超出了图像..现在它的工作...谢谢朋友...
    • @roni 是的,这是可能的。我需要更新我的帖子。不过现在做不到。完成后我会发消息
    • @roni - 完成。如果你觉得我的帖子有用,别忘了点赞。祝你好运!
    【解决方案2】:

    我个人需要使用彩色图像,所以我想我会为不同尺寸的图像发布代码,但适用于彩色图像实现(请注意,点现在是 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
    

    【讨论】:

    • @runDOSrun 评论已删除,我的评价不好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 2017-09-11
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多