标签:black pen point vector clear 公式 key 通道 保存
# -*- coding: utf-8 -*- import numpy from PIL import Image image = Image.open("5.gif") heigh = image.size[0] weigh = image.size[1] checkbox = ([-1,0],[0,1],[1,0],[0,-1]) #降噪除去一个点 def clearpoint(im): for i in range(heigh): for j in range(weigh): if im.getpixel((i,j))==0: result = 0 for count in range(4): if im.getpixel((i+checkbox[count][0],j+checkbox[count][1])):result+=1 if result == 4: im.putpixel((i,j),255) return im box = numpy.array([0,0,13,20]) imagenumsit = [] #chun cun 5 ge shuzi imagenumbit = [] imagedoublevalue = image.convert("1") imagedoublevalue = clearpoint(imagedoublevalue) resultnum = 0 for i in range(5): imagenum = imagedoublevalue.crop(box) imagenumsit.append(imagenum) box[0]=box[2] box[2]+=9 for i in range(5): w = imagenumsit[i].size[0] h = imagenumsit[i].size[1] vector = [0]*w imagenumbitsingle = numpy.tile(vector,(h,1)) for x in range(h): for y in range(w): if imagenumsit[i].getpixel((y,x)) == 0:imagenumbitsingle[x][y]=1 imagenumbit.append(imagenumbitsingle) imagenumsit[1].show() print imagenumbit[1]
代码用来分隔图像并且把图像二值化,分别保存。
python代码实现记录:
标签:black pen point vector clear 公式 key 通道 保存
原文地址:http://www.cnblogs.com/tiemuer/p/7875513.html