卡在Matlab的子图机制上,用于匹配vlfeat的图像点

时间:2012-11-09 09:36:45

标签: matlab computer-vision sift image-comparison vlfeat

我正在使用Matlab进行vlfeat,我正在关注这个问题here

以下是我的简单测试图片:

左图:

L

右图:

R

我在这里用2个简单的图像做了一个简单的测试(右图像只是左边的旋转版本),我得到了相应的结果:

test

它有效,但我还有一个要求,即匹配两个图像的SIFT点并显示它们,如下所示:

likethis

我确实理解vl_ubcmatch返回2个匹配索引数组,并且映射它们不是一个问题,哪个点到达两个图像上的哪个点。但是,我目前陷入了matlab的程序。我找到了this。但这只有在子图保持这种情况下才有效。将图像添加到子图中时,大小会更改,并且标准化失败。

这是我的代码:( im和im2是图像.f,d和f2,d2分别来自vl_sift函数的帧和描述符,来自2个图像)

    [matches score] = vl_ubcmatch(d,d2,threshold);%threshold originally is 1.5

if (mode >= 2)%verbose 2

    subplot(211);
    imshow(uint8(im));
    hold on;
    plot(f(1,matches(1,:)),f(2,matches(1,:)),'b*');

    subplot(212);
    imshow(uint8(im2));
    hold on;
    plot(f2(1,matches(2,:)),f2(2,matches(2,:)),'g*');

end

if (mode >= 3)%verbose 3

     [xa1 ya1] = ds2nfu(  f(1,matches(1,:)),  f(2,matches(1,:)));
     [xa2 ya2] = ds2nfu( f2(1,matches(2,:)), f2(2,matches(2,:)));

    for k=1:numel(matches(1,:))

        xxa1 = xa1(1, k);
        yya1 = ya1(1, k);
        xxa2 = xa2(1, k);
        yya2 = ya2(1, k);

        annotation('line',[xxa1 xxa2],[yya1 yya2],'color','r');
    end
end

上面的代码产生了这个:

an

我认为subplot不是一个很好的方式去做这样的事情。在Matlab中有更好的方法吗?如果可能的话,我想要一个类似于空面板的东西,我可以绘制我的图像,自由地绘制线条和自由缩放,就像以OpenGL风格绘制2D游戏一样。

2 个答案:

答案 0 :(得分:8)

从zplesivcak的建议,是的,这是可能的,毕竟不是那个问题。这是代码:

%  After we have applied vl_sift with 2 images, we will get frames f,f2, 
%  and descriptor d,d2 of the images. After that, we can apply it into 
%  vl_ubcmatch to perform feature matching:

[matches score] = vl_ubcmatch(d,d2,threshold); %threshold originally is 1.5

% check for sizes and take longest width and longest height into
% account
if (size(im,1) > size(im2,1))
    longestWidth = size(im,1);       
else
    longestWidth = size(im2,1);
end

if (size(im,2) > size(im2,2))
    longestHeight = size(im,2);
else
    longestHeight = size(im2,2);
end


% create new matrices with longest width and longest height
newim = uint8(zeros(longestWidth, longestHeight, 3)); %3 cuz image is RGB
newim2 = uint8(zeros(longestWidth, longestHeight, 3));

% transfer both images to the new matrices respectively.
newim(1:size(im,1), 1:size(im,2), 1:3) = im;
newim2(1:size(im2,1), 1:size(im2,2), 1:3) = im2;

% with the same proportion and dimension, we can now show both
% images. Parts that are not used in the matrices will be black.
imshow([newim newim2]);

hold on;

    X = zeros(2,1);
    Y = zeros(2,1);

    % draw line from the matched point in one image to the respective matched point in another image.
    for k=1:numel(matches(1,:))

        X(1) = f(1, matches(1, k));
        Y(1) = f(2, matches(1, k));
        X(2) = f2(1, matches(2, k)) + longestHeight; % for placing matched point of 2nd image correctly.
        Y(2) = f2(2, matches(2, k));

        line(X,Y);

    end

以下是测试用例:

tc

通过修改问题中其中一个图像的画布宽度和高度,我们看到上面的算法将处理并相应地显示图像。未使用的区域将是黑色的。此外,我们看到该算法可以分别匹配两个图像的特征。

修改

另外,Maurits建议,为了更清洁和更好地实施,请查看Lowe SIFT matlab wrappers

答案 1 :(得分:3)

如果您的光盘上已安装了Matlab计算机视觉库,您只需使用

即可
M1 = [f(1, match(1, :)); f(2, match(1, :)); ones(1, length(match))];
M2 = [f2(1, match(2, :)); f2(2, match(2, :)); ones(1, length(match))];

showMatchedFeatures(im,im2,[M1(1:2, :)]',[M2(1:2, :)]','montage','PlotOptions',{'ro','g+','b-'} );