Python Image 二值化初测

#!/usr/bin/python
import sys
import Image

def main():
    if len(sys.argv) < 2:
        filename = '1.bmp'
    else:
        filename = sys.argv[1]
    im = Image.open(filename)
    im = im.convert('RGBA')
    x, y = im.size
    pixdata = im.load()
    for j in xrange(y):
        for i in xrange(x):
            if pixdata[i,j][0] < 90 and pixdata[i,j][1] < 136 and pixdata[i,j][2] > 0:
                print '@',
            else:
                print '-',
        print ''

if __name__ == '__main__':
    main();

 测试用图 

 

 

posted @ 2013-04-11 23:42  aboys  阅读(816)  评论(0编辑  收藏  举报