小編給大家分享一下python如何實現(xiàn)圖片二值化及灰度處理方式,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
我就廢話不多說了,直接上代碼吧!
集成環(huán)境:win10 pycharm
#!/usr/bin/env python3.5.2 # -*- coding: utf-8 -*- '''4圖片灰度調(diào)整及二值化: 集成環(huán)境:win10 python3 Pycharm ''' from PIL import Image # load a color image im = Image.open('picture\\haha.png' )#當(dāng)前目錄創(chuàng)建picture文件夾 # convert to grey level image Lim = im.convert('L' ) Lim.save('pice.jpg' ) # setup a converting table with constant threshold threshold = 185 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) # convert to binary image by the table bim = Lim.point(table, '1' ) bim.save('picf.png' )
看完了這篇文章,相信你對“python如何實現(xiàn)圖片二值化及灰度處理方式”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!