Kar*_*arl 5 matlab image-comparison computer-vision sift vlfeat
我在Matlab做vlfeat,我在这里关注这个问题.
以下是我的简单测试图像:
左图:

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

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

我确实理解vl_ubcmatch返回2个匹配索引数组,并且映射它们不是一个问题,哪个点到达两个图像上的哪个点.但是,我目前陷入了matlab的程序.我找到了这个.但这只有在子图保持这种情况下才有效.将图像添加到子图中时,大小会更改,并且标准化失败.
这是我的代码:(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
Run Code Online (Sandbox Code Playgroud)
上面的代码产生了这个:

我认为subplot不是一个很好的方法来做这样的事情.在Matlab中有更好的方法吗?如果可能的话,我想要一个类似于空面板的东西,我可以绘制我的图像,自由地绘制线条和自由缩放,就像以OpenGL风格绘制2D游戏一样.
从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
Run Code Online (Sandbox Code Playgroud)
以下是测试用例:

通过修改问题中其中一个图像的画布宽度和高度,我们看到上面的算法将处理并相应地显示图像.未使用的区域将是黑色的.此外,我们看到该算法可以分别匹配两个图像的特征.
编辑:
或者,由Maurits建议,为了更清洁和更好的实施,请查看Lowe SIFT matlab包装.