因此,基本上,我正在尝试将彼此重叠的两个图像组合在一起。我已使用注册估算器应用程序进行检查,并且它们具有匹配的功能。 目前,我的程序选择了匹配的功能并将其显示,其他图像则显示在背景中。 我想做的是能够复制注册估算器应用程序的工作,并在功能相交的地方合并两个图像。
我看了一个全景示例,但无论出于何种原因,它似乎都不起作用。
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
所以基本上我需要做的是能够创建一个新图像并将其写入,这是两个图像的组合图像。有点像全景,但不是因为它们恰好在点相交并重叠的地方
答案 0 :(得分:0)
我认为您从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'
可能会有所帮助。