指南
本篇主要內容是如何用代碼實現GF1WFV遙感數據配准,同時也適用於其他類型的圖像校正,拼接。
本篇原理是surf自動特征提取,這個算法是SIFT的一種改進
配准效果用標准誤差RMSE進行定量化度量
展示如何批量配准圖像
完整代碼及部分GF1WFV數據下載見github
配准算法流程
1.計算SURF特征
2.提取特征描述子
3.匹配特征描述子
4.有效特征描述子在原圖中的對應位置
5.計算變換矩陣參數
6.配准
讀取圖像
data1=imread(file1);%參考圖像
data2=imread(file2);%待配准的圖像
1. 計算SURF特征
計算圖像的SURF特征,並返回SURF點對象
ptsOriginal = detectSURFFeatures(original,'MetricThreshold',MetricThreshold);
ptsDistorted = detectSURFFeatures(distorted,'MetricThreshold',MetricThreshold);
輸入參數:
- I–大小為MxN的灰度圖像矩陣
- ‘MetricThreshold’– 最強特征閾值默認值1000,減小閾值得到更多的斑點特征(blob feature)
‘NumOctaves’–層數(octaves),默認值為3,要求至少大於等於1。層數增加,能夠發現更大的斑點。不同尺度圖像,適合的層數不同。例如50X50的圖像,層數不必過高小於等於2即可。
‘NumScaleLevels’–每一層需要計算的不同尺度數目。默認值4,此參數值越大,檢測斑點特征越多。
‘ROI’–感興趣的矩形區域,默認值[1,1,size(I,2),size(I,1)]。輸入是一個向量,表示從左上角的點(x,y)開始,大小為(width,height)的矩陣。
2. 提取特征描述子
提取參考圖像和待配准圖像的特征向量也被稱為描述(descriptors),以及他們對應的坐標
[featuresOriginal, validPtsOriginal] = extractFeatures(original,ptsOriginal );
[featuresDistorted, validPtsDistorted] = extractFeatures(distorted,ptsDistorted );
輸出參數:
validPtsOriginal–輸出特征描述子featuresOriginal中,刪除一些在圖像區域外,太靠近邊界的匹配特征后剩余的有效特征。
3. 匹配特征描述子
返回兩個特征集中最類似特征的對應位置索引,返回矩陣大小Px2。P的大小和特征個數一致
indexPairs = matchFeatures(featuresOriginal, featuresDistorted);
4. 有效特征描述子在原圖中的對應位置
matchedOriginal = validPtsOriginal(indexPairs(:,1));
matchedDistorted = validPtsDistorted(indexPairs(:,2));
showMatchedFeatures(original(:,:,3:-1:1),distorted(:,:,3:-1:1),matchedOriginal,matchedDistorted);
title('Putatively matched points (including outliers)');
可以看到,此時得到的匹配特征描述子包含一些錯誤的點
5. 計算變換矩陣
[tform, inlierDistorted, inlierOriginal] = estimateGeometricTransform(matchedDistorted, matchedOriginal, 'affine');
輸入參數:
‘affine’是變換的類型,包括3種’similarity’,’affine’,’projective’
輸出參數:
tform是一個對象,tform.T是將待配准圖像和參考圖像配准的變換矩陣
inlierDistorted 是matchedDistorted中剔除了異常點后的匹配點。如下圖所示
6.配准
outputView = imref2d(size(original));
recovered = imwarp(ditorted,tform,'linear','OutputView',outputView);
輸入參數:
- ditorted 待配准的圖像
- tform 變換矩陣對象
- ‘linear’變換后的插值方法。包括’linear’,’nearest’,’cubic’
輸出參數:
-recovered 配准后的圖像
展示配准后的結果:
figure, imshowpair(original(:,:,1:3),recovered(:,:,1:3),'ColorChannels','red-cyan')
title([file2(1:8) ,' Adjusted in linear']);
6.批量配准圖像
file1='20160519cut.jp2';%參考圖像名稱
path='F:\多時相\高分1寬幅';
list=dir(fullfile([path '\*.jp2']));%文件下所有的圖像名稱
filenum=length(list);
j=1;
for i=1:filenum
file2=list(i).name;
[original,recovered]=register([path,'\',file1],[path,'\',file2]); figure, imshowpair(original(:,:,1:3),recovered(:,:,1:3),'ColorChannels','red-cyan') title([file2(1:8) ,' Adjusted in linear']); imwrite(recovered,[path,'\配准\',file2(1:8),'.png'],'bitdepth',16); end