画像中のオブジェクト​を外接線で囲むにはど​のようにすればよいで​すか?

9 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 25 de Oct. de 2013
Respondida: MathWorks Support Team el 25 de Oct. de 2013
画像処理でよく用いられる "オブジェクトを外接線で囲む" 方法を教えて下さい。

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 25 de Oct. de 2013
"bwlabel"関数で個々のオブジェクトにラベル付けを行った後、"regionprops"関数を用いてオブジェクトを囲む外接線情報を取得することができます。
上記では、外接線(長方形)の左上端点のx軸、y軸座標および幅、高さからなる 1x4 のサイズを持つベクトルが生成されます。
rectangle関数を用いることで、表示された画像に外接線を上書きすることができます。
I = imread('coins.png'); % サンプル画像読み込み
% 2値化
level = graythresh(I);
BW = im2bw(I,level);
BW1 = imfill(BW,'holes'); % オブジェクトの塗り潰し
Label = bwlabel(BW1,4); % ラベリング処理
   
prop = regionprops(Label,'BoundingBox'); % 外枠線情報の取得
imshow(I) % 入力画像表示
% 外枠線の描画処理   
for s = 1:length(prop)
h(s)=rectangle('Position',prop(s).BoundingBox);
set(h(s),'EdgeColor','g')
end

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!