資源簡介
這個代碼用于數字圖像處理中的圖像拼接,幾幅具有公共區域的圖像可以拼接成一幅全圖。
代碼片段和文件信息
%?Load?images.
buildingDir?=?fullfile(toolboxdir(‘vision‘)?‘visiondata‘?‘building‘);
buildingScene?=?imageDatastore(buildingDir);
%?Display?images?to?be?stitched
montage(buildingScene.Files)
%?Read?the?first?image?from?the?image?set.
I?=?readimage(buildingScene?1);
%?Initialize?features?for?I(1)
grayImage?=?rgb2gray(I);
points?=?detectSURFFeatures(grayImage);
[features?points]?=?extractFeatures(grayImage?points);
%?Initialize?all?the?transforms?to?the?identity?matrix.?Note?that?the
%?projective?transform?is?used?here?because?the?building?images?are?fairly
%?close?to?the?camera.?Had?the?scene?been?captured?from?a?further?distance
%?an?affine?transform?would?suffice.
numImages?=?numel(buildingScene.Files);
tforms(numImages)?=?projective2d(eye(3));
%?Iterate?over?remaining?image?pairs
for?n?=?2:numImages
????%?Store?points?and?features?for?I(n-1).
????pointsPrevious?=?points;
????featuresPrevious?=?features;
????%?Read?I(n).
????I?=?readimage(buildingScene?n);
????%?Detect?and?extract?SURF?features?for?I(n).
????grayImage?=?rgb2gray(I);
????points?=?detectSURFFeatures(grayImage);
????[features?points]?=?extractFeatures(grayImage?points);
????%?Find?correspondences?between?I(n)?and?I(n-1).
????indexPairs?=?matchFeatures(features?featuresPrevious?‘Unique‘?true);
????matchedPoints?=?points(indexPairs(:1)?:);
????matchedPointsPrev?=?pointsPrevious(indexPairs(:2)?:);
????%?Estimate?the?transformation?between?I(n)?and?I(n-1).
????tforms(n)?=?estimateGeometricTransform(matchedPoints?matchedPointsPrev...
????????‘projective‘?‘Confidence‘?99.9?‘MaxNumTrials‘?2000);
????%?Compute?T(1)?*?...?*?T(n-1)?*?T(n)
????tforms(n).T?=?tforms(n-1)
評論
共有 條評論