Main Content

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

watershed

説明

watershed 変換は、明るいピクセルが高い高度、暗いピクセルが低い高度を表す表面として扱うことにより、イメージ内の "集水域 (catchment basins)" または "流域の稜線 (watershed ridge lines)" を検出します。watershed 変換を使用して、連続する関心領域を個別のオブジェクトにセグメント化できます。

L = watershed(A) は、入力行列 A の watershed 領域を指定するラベル行列 L を返します。

L = watershed(A,conn) は watershed 計算で使用する連結性を指定します。

すべて折りたたむ

オーバーラップした 2 つの円形オブジェクトが含まれるバイナリ イメージを作成します。イメージを表示します。

center1 = -40;
center2 = -center1;
dist = sqrt(2*(2*center1)^2);
radius = dist/2 * 1.4;
lims = [floor(center1-1.2*radius) ceil(center2+1.2*radius)];
[x,y] = meshgrid(lims(1):lims(2));
bw1 = sqrt((x-center1).^2 + (y-center1).^2) <= radius;
bw2 = sqrt((x-center2).^2 + (y-center2).^2) <= radius;
bw = bw1 | bw2;
imshow(bw)
title('Binary Image with Overlapping Objects')

Figure contains an axes object. The axes object with title Binary Image with Overlapping Objects contains an object of type image.

バイナリ イメージの補数の距離変換を計算します。出力イメージの各ピクセルの値は、そのピクセルから bw 内の最も近い非ゼロ ピクセルまでの距離です。

D = bwdist(~bw);
imshow(D,[])
title('Distance Transform of Binary Image')

Figure contains an axes object. The axes object with title Distance Transform of Binary Image contains an object of type image.

Watershed 変換の場合に明るいピクセルが高い高度、暗いピクセルが低い高度を表すように、距離変換されたイメージの補数を取ります。

D = -D;
imshow(D,[])
title('Complement of Distance Transform')

Figure contains an axes object. The axes object with title Complement of Distance Transform contains an object of type image.

Watershed 変換を計算します。ROI の外側にあるピクセルを 0 に設定します。

L = watershed(D);
L(~bw) = 0;

結果として得られるラベル行列を RGB イメージとして表示します。

rgb = label2rgb(L,'jet',[.5 .5 .5]);
imshow(rgb)
title('Watershed Transform')

Figure contains an axes object. The axes object with title Watershed Transform contains an object of type image.

オーバーラップする 2 つ球が含まれる 3 次元バイナリ イメージを作成します。

center1 = -10;
center2 = -center1;
dist = sqrt(3*(2*center1)^2);
radius = dist/2 * 1.4;
lims = [floor(center1-1.2*radius) ceil(center2+1.2*radius)];
[x,y,z] = meshgrid(lims(1):lims(2));
bw1 = sqrt((x-center1).^2 + (y-center1).^2 + ...
           (z-center1).^2) <= radius;
bw2 = sqrt((x-center2).^2 + (y-center2).^2 + ...
           (z-center2).^2) <= radius;
bw = bw1 | bw2;
figure, isosurface(x,y,z,bw,0.5), axis equal, title('BW')
xlabel x, ylabel y, zlabel z
xlim(lims), ylim(lims), zlim(lims)
view(3), camlight, lighting gouraud

Figure contains an axes object. The axes object with title BW, xlabel x, ylabel y contains an object of type patch.

距離変換を計算します。

D = bwdist(~bw);
figure, isosurface(x,y,z,D,radius/2), axis equal
title('Isosurface of distance transform')
xlabel x, ylabel y, zlabel z
xlim(lims), ylim(lims), zlim(lims)
view(3), camlight, lighting gouraud

Figure contains an axes object. The axes object with title Isosurface of distance transform, xlabel x, ylabel y contains an object of type patch.

距離変換の補数を計算し、オブジェクトでないピクセルを Inf に強制し、watershed 変換を計算します。

D = -D;
D(~bw) = Inf;
L = watershed(D);
L(~bw) = 0;
figure
isosurface(x,y,z,L==1,0.5)
isosurface(x,y,z,L==2,0.5)
axis equal
title('Segmented objects')
xlabel x, ylabel y, zlabel z
xlim(lims), ylim(lims), zlim(lims)
view(3), camlight, lighting gouraud

Figure contains an axes object. The axes object with title Segmented objects, xlabel x, ylabel y contains 2 objects of type patch.

入力引数

すべて折りたたむ

入力イメージ。任意の次元の数値配列または logical 配列として指定します。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

ピクセルの連結性。次の表のいずれかの値を指定します。既定の連結性は 2 次元イメージでは 8、3 次元イメージでは 26 です。

平均

2 次元連結性

4

ピクセルのエッジの部分が接触している場合、ピクセルは連結されます。ピクセルの近傍は水平方向または垂直方向に隣接するピクセルです。

3-by-3 pixel neighborhood with four pixels connected to the center pixel

現在のピクセルを灰色で示します。

8

ピクセルのエッジまたはコーナーが接触している場合、ピクセルは連結されます。ピクセルの近傍は水平方向、垂直方向または対角方向に隣接するピクセルです。

3-by-3 pixel neighborhood with 8 pixels connected to the center pixel

現在のピクセルを灰色で示します。

3 次元連結性

6

面が接触している場合、ピクセルは連結されます。ピクセルの近傍は次のように隣接するピクセルです。

  • 次のいずれかの方向: 奥、手前、左、右、上および下

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces of the center pixel

現在のピクセルを灰色で示します。

18

面またはエッジが接触している場合、ピクセルは連結されます。ピクセルの近傍は次のように隣接するピクセルです。

  • 次のいずれかの方向: 奥、手前、左、右、上および下

  • 右下または上の奥など、2 つの方向の組み合わせ

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces and 12 pixels connected to the edges of the center pixel

現在のピクセルは立方体の中心です。

26

面、エッジまたはコーナーが接触している場合、ピクセルは連結されます。ピクセルの近傍は次のように隣接するピクセルです。

  • 次のいずれかの方向: 奥、手前、左、右、上および下

  • 右下または上の奥など、2 つの方向の組み合わせ

  • 右上の奥または左下の奥など、3 つの方向の組み合わせ

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces, 12 pixels connected to the edges, and 8 pixels connected to the corners of the center pixel

現在のピクセルは立方体の中心です。

高次元の場合、watershed は既定値 conndef(ndims(A),'maximal') を使用します。

連結性は、01 から成る 3 × 3 × ... × 3 行列を指定し、任意の次元に対してより一般的に定義することもできます。1 の値を持つ要素は、conn の中心要素に対する近傍の位置を定義します。conn は、その中心要素に関して対称でなければなりません。詳細については、カスタム連結性の定義を参照してください。

メモ

既定以外の連結性を設定した場合、イメージのエッジ上のピクセルは、境界上のピクセルであるとは見なされません。たとえば、conn = [0 0 0; 1 1 1; 0 0 0] の場合、最初と最後の行の上の要素は、連結性の定義に従って、イメージの外側の領域と接続していないため境界のピクセルとは見なされません。

データ型: double | logical

出力引数

すべて折りたたむ

ラベル行列。非負の整数の数値配列として指定します。0 とラベル付けされた要素は、固有の watershed 領域には属しません。1 とラベル付けされた要素は、最初の watershed 領域に属し、2 とラベル付けされた要素は、2 番目の watershed 領域に属する、というようになります。

ヒント

  • この関数で使用される watershed 変換アルゴリズムは、Image Processing Toolbox™ ソフトウェアのVersion 5.4 (R2007a) で変更されています。以前のアルゴリズムにより、連続的ではない、ラベルの付いた watershed 領域が生成される場合があります。以前のアルゴリズムと同じ結果を得る必要がある場合は、関数 watershed_old を使用してください。

  • オーバーセグメンテーションを防ぐには、関数 watershed を使用する前に関数 imhmin を使用して、浅い位置にある最小値をイメージから削除します。

アルゴリズム

watershed は Fernand Meyer アルゴリズムを使用します [1]

参照

[1] Meyer, Fernand, "Topographic distance and watershed lines,” Signal Processing , Vol. 38, July 1994, pp. 113-125.

拡張機能

バージョン履歴

R2006a より前に導入

すべて展開する