Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

キャリブレーションされていないステレオイメージの平行化

この例では、カメラの内部パラメーターが不明な場合に、関数estimateFundamentalMatrixestimateStereoRectification、およびdetectSURFFeaturesを使用して 2 つのキャリブレーションされていないイメージの平行化を計算する方法を説明します。

ステレオ イメージの平行化では、各イメージの対応する点が同じ行座標をもつような方法で、イメージが共通のイメージ平面に投影されます。この処理は、2 次元ステレオ対応点探索問題が 1 次元の問題に縮小されるため、ステレオ ビジョンの処理に役立ちます。たとえば、ステレオ イメージの平行化はアナグリフ イメージの計算や作成の前処理手順としてよく使用されます。詳細については、ステレオ ビデオからの深度推定の例を参照してください。

手順 1: ステレオ イメージのペアの読み取り

異なる位置から撮影された、同じシーンの 2 つのカラー イメージを読み取ります。続いて、イメージをグレースケールに変換します。マッチング プロセスに色は不要です。

I1 = imread("yellowstone_left.png");
I2 = imread("yellowstone_right.png");

% Convert to grayscale.
I1gray = im2gray(I1);
I2gray = im2gray(I2);

両方のイメージを並べて表示します。その後、イメージ間のピクセル単位の違いを示すカラー合成を表示します。

figure
imshowpair(I1,I2,"montage")
title("I1 (left); I2 (right)")

Figure contains an axes object. The axes object with title I1 (left); I2 (right) contains an object of type image.

figure 
imshow(stereoAnaglyph(I1,I2))
title("Composite Image (Red - Left Image, Cyan - Right Image)")

Figure contains an axes object. The axes object with title Composite Image (Red - Left Image, Cyan - Right Image) contains an object of type image.

イメージ間には明らかに向きと位置のオフセットが見られます。平行化の目的は、両方のイメージ内で対応する点が同じ行に表示されるようにイメージの位置を合わせることです。

手順 2: 各イメージからの関心点の収集

平行化のプロセスには 2 つのイメージ間における一連の点の対応関係が必要です。こうした対応関係を生成するには、両方のイメージから関心点を集め、両者間でマッチする可能性のあるものを選択します。detectSURFFeatures を使用して、両方のイメージでブロブのような特徴を探します。

blobs1 = detectSURFFeatures(I1gray,MetricThreshold=2000);
blobs2 = detectSURFFeatures(I2gray,MetricThreshold=2000);

I1 および I2 で最も強い 30 個の SURF 特徴量について、位置とスケールを可視化します。検出された特徴をすべてはマッチングできない点に注意してください。これは、両方のイメージでは検出されない特徴や、カメラの動きが原因で片方のイメージには表示されない特徴があるためです。

figure 
imshow(I1)
hold on
plot(selectStrongest(blobs1,30))
title("Thirty Strongest SURF Features In I1")

Figure contains an axes object. The axes object with title Thirty Strongest SURF Features In I1 contains 3 objects of type image, line. One or more of the lines displays its values using only markers

figure
imshow(I2)
hold on
plot(selectStrongest(blobs2,30))
title("Thirty Strongest SURF Features In I2")

Figure contains an axes object. The axes object with title Thirty Strongest SURF Features In I2 contains 3 objects of type image, line. One or more of the lines displays its values using only markers

手順 3: 点の推定的対応関係の検出

関数 extractFeatures および matchFeatures を使用して、点の推定的対応関係を見つけます。各ブロブについて SURF 特徴量ベクトル (記述子) を計算します。

[features1,validBlobs1] = extractFeatures(I1gray,blobs1);
[features2,validBlobs2] = extractFeatures(I2gray,blobs2);

差の絶対値の和 (SAD) をメトリクスとして使い、マッチする特徴のインデックスを求めます。

indexPairs = matchFeatures(features1,features2,Metric="SAD", ...
  MatchThreshold=5);

各イメージについてマッチする点の位置を取得します。

matchedPoints1 = validBlobs1(indexPairs(:,1),:);
matchedPoints2 = validBlobs2(indexPairs(:,2),:);

ステレオ イメージを組み合わせた合成イメージ上に、マッチする点を表示します。マッチの大部分は正いものですが、外れ値もいくつかあります。

figure 
showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2)
legend("Putatively Matched Points In I1","Putatively Matched Points In I2")

Figure contains an axes object. The axes object contains 4 objects of type image, line. One or more of the lines displays its values using only markers These objects represent Putatively Matched Points In I1, Putatively Matched Points In I2.

手順 4: エピポーラ制約を使用した外れ値の削除

正しくマッチしている点は、エピポーラ制約を満たしていなければなりません。これは、各点が、その対応する点によって決定されるエピポーラ線上になければならないということです。関数 estimateFundamentalMatrix を使用して基礎行列を計算し、エピポーラ制約を満たすインライアを見つけます。

[fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(...
  matchedPoints1,matchedPoints2,Method="RANSAC", ...
  NumTrials=10000,DistanceThreshold=0.1,Confidence=99.99);
  
if status ~= 0 || isEpipoleInImage(fMatrix,size(I1)) ...
  || isEpipoleInImage(fMatrix',size(I2))
  error(["Not enough matching points were found or "...
         "the epipoles are inside the images. Inspect "...
         "and improve the quality of detected features ",...
         "and images."]);
end

inlierPoints1 = matchedPoints1(epipolarInliers, :);
inlierPoints2 = matchedPoints2(epipolarInliers, :);

figure
showMatchedFeatures(I1, I2, inlierPoints1, inlierPoints2)
legend("Inlier Points In I1","Inlier Points In I2")

Figure contains an axes object. The axes object contains 4 objects of type image, line. One or more of the lines displays its values using only markers These objects represent Inlier Points In I1, Inlier Points In I2.

手順 5: イメージの平行化

関数 estimateStereoRectification を使用して平行化変換を計算します。これを使用すると、対応する各点が同じ行に表示されるようにイメージを変換できます。

[tform1, tform2] = estimateStereoRectification(fMatrix, ...
  inlierPoints1.Location,inlierPoints2.Location,size(I2));

ステレオ イメージを平行化し、ステレオ アナグリフとして表示します。赤とシアンの立体眼鏡を使用して、3 次元効果を確認することができます。

[I1Rect, I2Rect] = rectifyStereoImages(I1,I2,tform1,tform2);
figure
imshow(stereoAnaglyph(I1Rect,I2Rect))
title("Rectified Stereo Images (Red - Left Image, Cyan - Right Image)")

Figure contains an axes object. The axes object with title Rectified Stereo Images (Red - Left Image, Cyan - Right Image) contains an object of type image.

手順 6: 平行化プロセスの一般化

上記の手順で使用したパラメーターは、2 つの特定のステレオ イメージに合わせて設定されています。他のイメージを処理するには関数 cvexRectifyStereoImages を使用できます。この関数には平行化パラメーターを自動調整する追加のロジックが含まれています。下記のイメージは、この関数を使ってイメージのペアを処理した結果を示したものです。

cvexRectifyImages("parkinglot_left.png","parkinglot_right.png");

Figure contains an axes object. The axes object with title Rectified Stereo Images (Red - Left Image, Cyan - Right Image) contains an object of type image.

参考文献

[1] Trucco, E; Verri, A. "Introductory Techniques for 3-D Computer Vision." Prentice Hall, 1998.

[2] Hartley, R; Zisserman, A. "Multiple View Geometry in Computer Vision." Cambridge University Press, 2003.

[3] Hartley, R. "In Defense of the Eight-Point Algorithm." IEEE® Transactions on Pattern Analysis and Machine Intelligence, v.19 n.6, June 1997.

[4] Fischler, MA; Bolles, RC. "Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography." Comm. Of the ACM 24, June 1981.