python实现图片二值化及灰度处理

来源:互联网 发布:fluent english软件 编辑:程序博客网 时间:2024/06/10 07:57

集成环境:win10  pycharm

#!/usr/bin/env python3.5.2# -*- coding: utf-8 -*-'''4图片灰度调整及二值化:集成环境:win10 python3 Pycharm'''from PIL import Image#  load a color imageim = Image.open('picture\\haha.png' )#当前目录创建picture文件夹#  convert to grey level imageLim = im.convert('L' )Lim.save('pice.jpg' )#  setup a converting table with constant thresholdthreshold = 185table = []for i in range(256):    if i < threshold:        table.append(0)    else:        table.append(1)# convert to binary image by the tablebim = Lim.point(table, '1' )bim.save('picf.png' )

原创粉丝点击