标签:
#coding:utf-8 #图像二值处理 import os from PIL import Image j=1 dirpath="./pic/" path = "./font/" img = Image.open(‘D:\\mobile\\hi.bmp‘) # 读入图片 img = img.convert("RGBA") pixdata = img.load() #二值化 for y in xrange(img.size[1]): for x in xrange(img.size[0]): if pixdata[x, y][0] < 90: pixdata[x, y] = (0, 0, 0, 255) for y in xrange(img.size[1]): for x in xrange(img.size[0]): if pixdata[x, y][1] < 136: pixdata[x, y] = (0, 0, 0, 255) for y in xrange(img.size[1]): for x in xrange(img.size[0]): if pixdata[x, y][2] > 0: pixdata[x, y] = (255, 255, 255, 255) img.save(‘D:\\mobile\\hi2.png‘)
参考链接:http://vipscu.blog.163.com/blog/static/18180837220134234528457/
标签:
原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/4816892.html