困扰Matlab的subplot机制匹配图像的点vlfeat [英] Getting stuck on Matlab's subplot mechanism for matching images' points for vlfeat

查看:315
本文介绍了困扰Matlab的subplot机制匹配图像的点vlfeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中做vlfeat,我正在关注这个问题。但是,只有当子地图保持那样的方式才有效。



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

  [matches score] = vl_ubcmatch(d,d2,threshold) ;%threshold原来是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 ,:)),f(2,matched(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);

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

上面的代码可以得到:





我认为subplot不是一个好办法去这样的东西。在Matlab中有更好的方法吗?如果可能,我想要一个像空面板,我可以画我的形象,自由地绘制线和自由放大,就像在2D的风格绘制2D游戏。

解决方案

从zplesivcak的建议,是的,这是可能的,而不是那么有问题。这是代码:

 %在我们应用vl_sift 2张图片后,我们将得到框架f,f2,
%和图像的描述符d,d2。之后,我们可以将它应用到
%vl_ubcmatch中以执行特征匹配:

[matches score] = vl_ubcmatch(d,d2,threshold); %threshold最初是​​1.5

%检查大小并将最长宽度和最长高度转换为
%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


%创建最长宽度和最长高度的新矩阵
newim = uint8(zeros(longestWidth,longestHeight,3)); %3 cuz图像是RGB
newim2 = uint8(zeros(longestWidth,longestHeight,3));

%分别将两个图像传输到新矩阵。
newim(1:size(im,1),1:size(im,2),1:3)
newim2(1:size(im2,1),1:size(im2,2),1:3)= im2;

%具有相同的比例和维度,我们现在可以同时显示
%图像。矩阵中未使用的零件将是黑色的。
imshow([newim newim2]);

hold on;

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

%从一个图像中的匹配点到另一个图像中的相应匹配点绘制线。
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; %,用于正确放置第二张图像的匹配点。
Y(2)= f2(2,matches(2,k));

line(X,Y);

end

这里是测试用例:





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



EDIT:



或者,由Maurits建议,为了更清洁和更好的实施,请查看 Lowe SIFT matlab封装


I am doing vlfeat in Matlab and I am following this question here.

These below are my simple testing images:

Left Image:

Right Image:

I did a simple test with 2 simple images here (the right image is just rotated version of the left), and I got the result accordingly:

It works, but I have one more requirement, which is to match the SIFT points of the two images and show them, like this:

I do understand that vl_ubcmatch returns 2 arrays of matched indices, and it is not a problem to map them for which point goes to which point on two images. However, I am currently stuck in matlab's procedure. I found this. But that only works if the subplot stays that way. When you add an image into the subplot, the size changes and the normalization failed.

Here is my code: (im and im2 are images. f, d and f2, d2 are frames and descriptors from vl_sift function from 2 images respectively)

    [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

The code above yields this:

I think subplot isn't a good way to go for something like this. Is there a better method for this in Matlab? If possible, I want something like an empty panel that I can draw my image, draw lines freely and zoom freely, just like drawing 2D games in OpenGL style.

解决方案

From zplesivcak's suggestion, yes, it is possible, and not that problematic after all. Here is the code:

%  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

Here is the test case:

By modifying the canvas width and height of one of the images from the question, we see that the algorithm above will take care of that and display the image accordingly. Unused area will be black. Furthermore, we see that the algorithm can match the features of two images respectively.

EDIT:

Alternatively, suggested by Maurits, for cleaner and better implementation, check out Lowe SIFT matlab wrappers.

这篇关于困扰Matlab的subplot机制匹配图像的点vlfeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆