Main Content

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

テンプレート マッチングを使用したイメージ内のオブジェクト位置の検出

参照イメージとテンプレート イメージを MATLAB ワークスペースに読み取ります。

img = imread('stopSignTest.jpg');
tempImg = imread('vipwarningsigns_stop_template.png');

イメージを表示します。参照イメージは一時停止標識看板を含むシーンです。テンプレートは、一時停止標識看板の低空間解像度イメージです。

figure
imshow(img)
title('Reference Image')
figure
imshow(tempImg)
title('Template')

Simulink® モデルを開きます。

modelname = 'ex_blktemplatematching.slx';
open_system(modelname)

モデルは、Image From Workspaceブロックを使用してイメージを読み取ります。テンプレート マッチングを実行するには、まずColor Space Conversionブロックを使用して入力カラー イメージを強度イメージに変換しなければなりません。次に、以下のパラメーター値に設定した Template Matching ブロックを使用して、参照イメージ内でテンプレート イメージの位置を検出します。

  • 一致メトリクス - Sum of absolute differences

  • 出力 - Best match location

  • 探索方法 - Three-step

Template Matching ブロックは、周囲のピクセル領域がテンプレート イメージと最もよく一致する参照イメージ内の位置を出力します。

モデルを実行します。

out = sim(modelname);

出力値を読み取ります。

location = out.simout;

円を描画し、最も一致するピクセル位置の周囲の領域を強調表示します。結果を表示します。

img = insertShape(img,'circle',[location(1) location(2) 20]);
figure
imshow(img);
hold on
plot(location(1),location(2),'*r')
title('Results of Template Matching')