好吧,在阅读了很多博客和所有内容之后,我已经尝试过这样做。我仍然不确定我这样做是否正确。如果发现有问题,请随时发表评论。为此,我使用了可以在此处找到的 mathworks fex 提交:ginputc函数。
matlab代码如下:
clc; clear all; close all;
% no of keypoint
N = 7;
I = imread('2.jpg');
I = rgb2gray(I);
[Gx, Gy] = imgradientxy(I, 'Sobel');
[Gmag, ~] = imgradient(Gx, Gy);
figure, imshow(Gmag, [ ]), title('Gradient magnitude')
I = Gmag;
[x,y] = ginputc(N, 'Color' , 'r');
matchedpoint1 = [x y];
J = imread('2.png');
[Gx, Gy] = imgradientxy(J, 'Sobel');
[Gmag, ~] = imgradient(Gx, Gy);
figure, imshow(Gmag, [ ]), title('Gradient magnitude')
J = Gmag;
[x, y] = ginputc(N, 'Color' , 'r');
matchedpoint2 = [x y];
[tform,inlierPtsDistorted,inlierPtsOriginal] = estimateGeometricTransform(matchedpoint2,matchedpoint1,'similarity');
figure; showMatchedFeatures(J,I,inlierPtsOriginal,inlierPtsDistorted);
title('Matched inlier points');
I = imread('2.jpg'); J = imread('2.png');
I = rgb2gray(I);
outputView = imref2d(size(I));
Ir = imwarp(J,tform,'OutputView',outputView);
figure; imshow(Ir, []);
title('Recovered image');
figure,imshowpair(I,J,'diff'),title('Difference with original');
figure,imshowpair(I,Ir,'diff'),title('Difference with restored');
步骤1
我使用 sobel 边缘检测器来提取深度和 rgb 图像的边缘,然后使用阈值来获取边缘图。我将主要只处理梯度幅度。这给了我两个图像:
![depth_edge](https://i.stack.imgur.com/mAkmS.png)
第2步
接下来我使用ginput
orginputc
函数在两个图像上标记关键点。点之间的对应关系是我事先建立的。我尝试使用SURF
功能,但它们在深度图像上效果不佳。
![在此处输入图像描述](https://i.stack.imgur.com/BC1og.png)
第 3 步
使用estimategeometrictransform
得到变换矩阵tform
,然后使用该矩阵恢复移动图像的原始位置。下一组图像讲述了这个故事。
![匹配的内部图像](https://i.stack.imgur.com/HMEQf.png)
![恢复的图像](https://i.stack.imgur.com/7SpsY.png)
![与原版的区别](https://i.stack.imgur.com/jpNq6.png)
![与恢复的区别](https://i.stack.imgur.com/L0XwQ.png)
当然,我仍然相信,如果任一图像中的关键点选择更加明智,结果可以进一步改善。我也认为@Specktre 方法更好。我只是注意到,与问题相比,我在答案中使用了单独的图像对。两张图片都来自同一个数据集,可在此处找到vap rgb-dt dataset。