加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 05:13:22 所属栏目:大数据 来源:网络整理
导读: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 tableim = Imag
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:Pyweekday01_22_hongzhacode55.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读