Main Content

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

テクスチャ フィルターを使ったテクスチャのセグメンテーション

この例では、テクスチャに基づいて領域を識別し、セグメント化する方法を示します。

イメージの読み取り

バッグのテクスチャ パターンのグレースケール イメージを読み取り、それを表示します。

I = imread('bag.png');
imshow(I)
title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

テクスチャ イメージの作成

関数 entropyfilt を使用して、テクスチャ イメージを作成します。関数 entropyfilt は、配列を出力します。ここで、各出力ピクセルは、入力イメージ I 内の対応するピクセル周辺に 9 行 9 列近傍のエントロピー値を含んでいます。エントロピーとは、ランダム性の統計的尺度です。

stdfilt および rangefilt を使用しても、同じようなセグメンテーション結果に達することができます。局所エントロピーのテクスチャ イメージを比較するため、局所的な標準偏差と局所範囲を示すテクスチャ イメージ S および R をそれぞれ作成します。

E = entropyfilt(I);
S = stdfilt(I,ones(9));
R = rangefilt(I,ones(9));

rescale を使用してテクスチャ イメージ E および S を再スケーリングし、ピクセル値がデータ型 double のイメージに期待される [0, 1] の範囲に収まるようにします。

Eim = rescale(E);
Sim = rescale(S);

3 つのテクスチャ イメージをモンタージュに表示します。

montage({Eim,Sim,R},'Size',[1 3],'BackgroundColor','w',"BorderSize",20)
title('Texture Images Showing Local Entropy, Local Standard Deviation, and Local Range')

Figure contains an axes object. The axes object with title Texture Images Showing Local Entropy, Local Standard Deviation, and Local Range contains an object of type image.

下部テクスチャでのマスクの作成

この例では、引き続きエントロピー テクスチャ イメージ Eim を処理します。その他のモルフォロジー関数を使用して、他の 2 種類のテクスチャ イメージについて同様の処理を繰り返しても、同じようなセグメンテーション結果に達することができます。

再スケーリングされたイメージ Eim をしきい値処理し、テクスチャをセグメント化します。テクスチャ間の境界線のピクセル強度値とほとんど同じであるため、しきい値 0.8 を選択します。

BW1 = imbinarize(Eim,0.8);
imshow(BW1)
title('Thresholded Texture Image')

Figure contains an axes object. The axes object with title Thresholded Texture Image contains an object of type image.

バイナリ イメージ BW1 のセグメント化されたオブジェクトは白色です。BW1I を比較した場合、上部テクスチャは過度にセグメント化され (複数の白色オブジェクト)、下部テクスチャはほとんど全体がセグメント化されていることに気が付きます。bwareaopen を使用して、上部テクスチャ内のオブジェクトを削除します。

BWao = bwareaopen(BW1,2000);
imshow(BWao)
title('Area-Opened Texture Image')

Figure contains an axes object. The axes object with title Area-Opened Texture Image contains an object of type image.

関数 imclose を使用して、エッジを滑らかにし、BWao のオブジェクトで開いている穴を閉じます。entropyfilt で使用したものと同じ 9 行 9 列近傍を指定します。

nhood = ones(9);
closeBWao = imclose(BWao,nhood);
imshow(closeBWao)
title('Closed Texture Image')

Figure contains an axes object. The axes object with title Closed Texture Image contains an object of type image.

関数 imfill を使用して、closeBWao のオブジェクトの穴を塗りつぶします。マスクはイメージの最下部まで拡張されていないため、下部テクスチャのマスクは完ぺきではありません。ただし、マスクを使用して、テクスチャをセグメント化できます。

mask = imfill(closeBWao,'holes');
imshow(mask);
title('Mask of Bottom Texture')

Figure contains an axes object. The axes object with title Mask of Bottom Texture contains an object of type image.

マスクを使用したテクスチャのセグメント化

テクスチャを 2 つの異なるイメージに分割します。

textureTop = I;
textureTop(mask) = 0;
textureBottom = I;
textureBottom(~mask) = 0;
montage({textureTop,textureBottom},'Size',[1 2],'BackgroundColor','w',"BorderSize",20)
title('Segmented Top Texture (Left) and Segmented Bottom Texture (Right)')

Figure contains an axes object. The axes object with title Segmented Top Texture (Left) and Segmented Bottom Texture (Right) contains an object of type image.

セグメンテーション結果の表示

ラベル行列を作成し、ラベル 1 のマスクを false、ラベル 2 のマスクを true とします。元のイメージ上にラベル行列を重ね合わせます。

L = mask+1;
imshow(labeloverlay(I,L))
title('Labeled Segmentation Regions')

Figure contains an axes object. The axes object with title Labeled Segmentation Regions contains an object of type image.

2 つのテクスチャ間の境界線の輪郭をシアンで表示します。

boundary = bwperim(mask);
imshow(labeloverlay(I,boundary,"Colormap",[0 1 1]))
title('Boundary Between Textures')

Figure contains an axes object. The axes object with title Boundary Between Textures contains an object of type image.

参考

| | | | | |