これは簡単な作業です。のPython
ようなライブラリをインストールする必要がありますnumpy
。scipy.ndimage
黒scipy.ndimage
の背景に任意の形状を抽出できるのはあなただけです。
したがって、画像が白い背景の場合は、最初に画像を反転する必要があります。これは簡単な作業です。
import scipy.ndimage
from scipy.misc import imread # so I can read the image as a numpy array
img=imread('image.png') # I assume your image is a grayscale image with a black bg.
labeled,y=scipy.ndimage.label(img) # this will label all connected areas(shapes).
#y returns how many shapes??
shapes=scipy.ndimage.find_objects(labeled)
# shapes returns indexing slices for ever shape
# So if you have 2 shapes in your image,then y=2.
# to extract the 1st shape you do like this.
first_shape=img[shapes[0]] # that's is a numpy feature if you are familiar with numpy .
second_shape=img[shapes[1]]
個々の形状を抽出した後、それが何であるかを識別するために実際にいくつかの数学的な作業を行うことができますか?(例えば、真円度比>>あなたはそれをグーグルすることができます、それはあなたの場合に役立ちます)