【问题标题】:Combining Two Images with Matching Features结合具有匹配特征的两个图像
【发布时间】:2019-05-22 20:12:45
【问题描述】:

所以基本上我正在尝试将两个相互重叠的图像组合在一起。我已使用注册估算器应用程序进行检查,它们具有匹配的功能。 目前我的程序会选择匹配的特征并显示它们,而另一张图像在背景中。 我想要做的是能够复制注册估计器应用程序所做的事情,并将它们的功能相遇的两个图像结合起来。

我查看了一个全景示例,但无论出于何种原因,它似乎都不起作用。

clear all;
close all;
I1 = rgb2gray(imread('q2.jpg'));
I2 = rgb2gray(imread('q20.jpg'));

points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);

[f1, vpts1] = extractFeatures(I1, points1);
[f2, vpts2] = extractFeatures(I2, points2);

indexPairs = matchFeatures(f1, f2) ;
matchedPoints1 = vpts1(indexPairs(:, 1));
matchedPoints2 = vpts2(indexPairs(:, 2));

figure; ax = axes;
showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2,'Parent',ax);
title(ax, 'Putative point matches');
legend(ax,'Matched points 1','Matched points 2');

% Create new Image ... 
% joinedImg = Combined image where matched points overlap

所以基本上我需要做的是能够创建一个新图像并将其imwrite,这是两个图像的组合图像。类似于全景图,但不是因为它只是点相遇和重叠的地方

【问题讨论】:

  • 这个问题需要澄清 - 尝试过做什么(您的代码)以及它在哪里失败(它做错了什么)。你认为相似的例子不算数。特别是对于您要完成的工作,您需要计算一个图像到另一个图像的投影,然后创建一个包含两者的更大图像,在交叉点您需要决定要采样的图像 - 第一个,第二个或两者的功能,例如平均。
  • 我不知道这就是为什么,我知道我可能必须在某处使用 imwarp 并调整大小,但不知道如何去做
  • 我已经很多年没有使用 Matlab 了,但是,图像处理完全是关于数学的,你并不需要一个库,只需将这两个图像视为简单的点并使用线性数学。附言不要忘记像素由 RGB 子像素组成,并且行通常以填充结束,以便它们除以 4Bytes(或者是 8?)。如果这仍然对您没有帮助,请尝试阅读/观看/参加有关实用图像处理的课程。

标签: image matlab image-processing image-stitching


【解决方案1】:

我认为您从 MATLAB 文档中选择了错误的示例。

您可以使用estimateGeometricTransform 示例。

下面的代码给你转换tform

[tform,inlierPtsDistorted,inlierPtsOriginal] = ...
    estimateGeometricTransform(matchedPtsDistorted,matchedPtsOriginal,...
    'similarity');

经编代码为:Ir = imwarp(distorted,tform,'OutputView',outputView);

为了融合图像,您可以使用imfuse 函数。

以下代码结合estimateGeometricTransform 示例和imfuse 示例:

%https://www.mathworks.com/help/vision/ref/estimategeometrictransform.html
original  = imread('cameraman.tif');
%imshow(original);
%title('Base image');
distorted = imresize(original,0.7); 
distorted = imrotate(distorted,31);
%figure; imshow(distorted);
%title('Transformed image');
ptsOriginal  = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal,validPtsOriginal] = extractFeatures(original,ptsOriginal);
[featuresDistorted,validPtsDistorted] = extractFeatures(distorted,ptsDistorted);
index_pairs = matchFeatures(featuresOriginal,featuresDistorted);
matchedPtsOriginal  = validPtsOriginal(index_pairs(:,1));
matchedPtsDistorted = validPtsDistorted(index_pairs(:,2));
%figure; 
%showMatchedFeatures(original,distorted, matchedPtsOriginal,matchedPtsDistorted);7
%title('Matched SURF points,including outliers');
[tform,inlierPtsDistorted,inlierPtsOriginal] = estimateGeometricTransform(matchedPtsDistorted,matchedPtsOriginal, 'similarity');
%figure; 
%showMatchedFeatures(original,distorted, inlierPtsOriginal,inlierPtsDistorted);
%title('Matched inlier points');
outputView = imref2d(size(original));
Ir = imwarp(distorted,tform,'OutputView',outputView);
%figure; imshow(Ir); 
%title('Recovered image');

%https://www.mathworks.com/help/images/ref/imfuse.html
C = imfuse(original, Ir, 'falsecolor', 'Scaling', 'joint', 'ColorChannels', [1 2 0]);
figure; imshow(C); 
title('fuse image');

%Write result image to file.
imwrite(C, 'fused.png');

如果您附上您的输入图像可能会有所帮助:'q2.jpg''q20.jpg'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多