import PIL from PIL import Image def get_bin_table(threshold=155): ‘‘‘ 获取灰度转二值的映射table 0表示黑色,1表示白色 ‘‘‘ table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) return table im = Image.open(r"D:\Py\week\day01_22_hongzha\code\55.jpg") im2 = im.convert("L") # im2.show() table = get_bin_table() binary = im2.point(table, ‘1‘) a = list(binary.getdata()) print(a) width,height = binary.size start = 0 step = width # 直接放在控制台输出 for i in range(height): for p in a[start:start+step]: if p==1: p =‘ ‘ print(p,end=‘‘) print() start+=step
原文地址:https://www.cnblogs.com/Skyda/p/10328430.html
时间: 2024-11-12 21:42:58