某位前辈的Image识图,,有点意思,先留存

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

猜你喜欢

转载自www.cnblogs.com/Skyda/p/10328430.html
今日推荐