ndimage.label(img)
import from packageを使用scipy
してグレースケールの PNG 画像にラベルを付けると、次のように動作します。
最初の画像: test_one
http://imageshack.us/a/img140/8669/onehx.png上記
の画像に対してこのコードを実行します。Photoshop
>>> from scipy.misc import imread
>>> from scipy.ndimage import (label,find_objects)
>>> img=imread('first.jpg')
>>> x,y = label(img)
>>> print y # Prints exactly "4" shapes ,which is right.
4
>>> f=find_objects(x)
>>> print f # Returns exactly the "4" slices of the considered shapes.
[(slice(16L, 61L, None), slice(149L, 189L, None)),
(slice(30L, 40L, None), slice(60L, 90L, None)),
(slice(50L, 70L, None), slice(20L, 120L, None)),
(slice(96L, 149L, None), slice(130L, 186L, None))]
今のところ、問題なく動作しています。
しかし、ここに示すように滑らかなブラシでシェイプを作成すると:
2 番目の画像:
test_one http://imageshack.us/a/img822/5696/twozg.png
2
番目の画像でこのコードを実行します
>>> from scipy.misc import imread
>>> from scipy.ndimage import (label,find_objects)
>>> img=imread('second.jpg')
>>> x,y = label(img)
>>>print y # Prints more than "5" shapes ,which is wrong.
6
>>> f=find_objects(x)
>>> print f # Return more than the "5" slices of the considered shapes.
#But still has the "5" slices of the "5" considered shapes
#among the other slices which I'm confused of.
[(slice(16L, 61L, None), slice(149L, 189L, None)),
(slice(30L, 40L, None), slice(60L, 90L, None)),
(slice(50L, 70L, None), slice(20L, 120L, None)),
(slice(96L, 149L, None), slice(130L, 186L, None)),
(slice(126L, 170L, None), slice(65L, 109L, None)),
(slice(127L, 128L, None), slice(79L, 80L, None))] #This is the extra object.
ndimage.label(img)
Smooth brush を使用したときに、考慮された形状よりも多くのラベルが付けられた理由を知りたいだけです。
はい、考慮される形状にラベルを付けることができますが、なぜ余分なラベル付けが必要なのか、余分なラベル付けされた形状を取り除くにはどうすればよいですか。
注:
(1)余分な形状は形状ではなく、薄い黒い領域のようなものです.!!
(2) 画像が RGB 形式の場合も同様に動作します。
(3)スムーズ ブラシで描画された形状のゼロ以外の値のパターンは、次のようになります。
>>> obj_6 #Not quite right but it's similar to this structure
array([[ 0, 0, 1, 1, 1, 1, 0, 0],
[ 0, 1, 6, 12, 15, 9, 3, 0],
[ 0, 7, 24, 50, 57, 35, 12, 1],
[ 2, 14, 52, 105, 119, 74, 24, 3],
[ 2, 16, 60, 122, 139, 86, 29, 4],
[ 1, 10, 37, 77, 88, 54, 18, 3],
[ 0, 3, 12, 25, 29, 18, 5, 1],
[ 0, 0, 1, 4, 5, 3, 1, 0]], dtype=uint8)
(4) 全体像を把握するには :
1:
2:
しばらくお待ちください。
更新 (1):
明確にするために、2 つの画像と関連する結果を投稿しました。