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
处理后的结果
Post Views: 14
Related Posts 3796