먼저, PIL로 문자 B의 이미지를 만들어 보자 :
import Image, ImageDraw, ImageFont
image = Image.new("RGBA", (600,150), (255,255,255))
draw = ImageDraw.Draw(image)
fontsize = 150
font = ImageFont.truetype("/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf", fontsize)
txt = 'B'
draw.text((30, 5), txt, (0,0,0), font=font)
img = image.resize((188,45), Image.ANTIALIAS)
print type(img)
plt.imshow(img)
당신이 특히 글꼴 경로, 그렇게 할 수있는 더 좋은 방법을 찾을 수 있습니다. 이미지를 생성하는 대신 이미지를로드하는 것이 좋습니다. 이제 
, 실수 부 : 어쨌든, 우리는 지금 작업하는 일이
import mahotas as mh
img = np.array(img)
im = img[:,0:50,0]
im = im < 128
skel = mh.thin(im)
noholes = mh.morph.close_holes(skel)
plt.subplot(311)
plt.imshow(im)
plt.subplot(312)
plt.imshow(skel)
plt.subplot(313)
cskel = np.logical_not(skel)
choles = np.logical_not(noholes)
holes = np.logical_and(cskel,noholes)
lab, n = mh.label(holes)
print 'B has %s holes'% str(n)
plt.imshow(lab)
을 그리고 우리는 콘솔 (ipython)에 있습니다 B가이 개 구멍
파이썬 사전을 사용하면 간단한 그래프를 구현하는 것이 쉽습니다. 다음은 [python docs의 예제]입니다 (http://www.python.org/doc/essays/graphs/). NetworkX는 결코 사용하지는 않았지만 과잉이라고 생각됩니다. 이미지를 그래프로 변환하는 것과 관련해서는 재미있는 문제인 것처럼 보이지만 간단한 방법으로는 알지 못합니다. 나는 이미지 조작을위한 많은 기능을 제공하는 [opencv] (http://opencv.org/)를 사용합니다. 당신은 그것에 유용한 일부를 찾을 수 있습니다. – KobeJohn