这是一项简单的任务,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]]
提取出您的个人形状后,您实际上可以做一些数学工作来确定它是什么?(例如循环比>>你可以谷歌它,它对你的情况有帮助)