def binarizing( img, threashold):
img = img. convert( "L") # 轉灰度
pixdata = img. load()
w, h = img. size
for y in range( h):
for x in range( w):
if pixdata[ x, y] < threashold:
pixdata[ x, y] = 0
else:
pixdata[ x, y] = 255
return img
def removeFrame( img, width):
'''
:param img:
:param width: 邊框的寬度
:return:
'''
w, h = img. size
pixdata = img. load()
for x in range( width):
for y in range( 0, h):
pixdata[ x, y] = 255
for x in range( w - width, w):
for y in range( 0, h):
pixdata[ x, y] = 255
for x in range( 0, w):
for y in range( 0, width):
pixdata[ x, y] = 255
for x in range( 0, w):
for y in range( h - width, h):
pixdata[ x, y] = 255
return img
處理後的結果
http://www.waitingfy.com/archives/3796