我就廢話不多說了,直接上代碼吧!
集成環境: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' )
以上這篇python實現圖片二值化及灰度處理方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網之家。
新聞熱點
疑難解答