溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python如何實(shí)現(xiàn)圖片二值化及灰度處理方式

發(fā)布時(shí)間:2021-03-24 11:05:51 來源:億速云 閱讀:261 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下python如何實(shí)現(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如何實(shí)現(xiàn)圖片二值化及灰度處理方式”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI