python 調(diào)整圖片亮度的示例
實(shí)現(xiàn)效果

實(shí)現(xiàn)代碼
import matplotlib.pyplot as plt
from skimage import io
file_name='D:/2020121173119242.png'
img=io.imread(file_name)
Increment = -10.0
img = img * 1.0
I = (img[:, :, 0] + img[:, :, 1] + img[:, :, 2])/3.0 + 0.001
mask_1 = I > 128.0
r = img [:, :, 0]
g = img [:, :, 1]
b = img [:, :, 2]
rhs = (r*128.0 - (I - 128.0) * 256.0) / (256.0 - I)
ghs = (g*128.0 - (I - 128.0) * 256.0) / (256.0 - I)
bhs = (b*128.0 - (I - 128.0) * 256.0) / (256.0 - I)
rhs = rhs * mask_1 + (r * 128.0 / I) * (1 - mask_1)
ghs = ghs * mask_1 + (g * 128.0 / I) * (1 - mask_1)
bhs = bhs * mask_1 + (b * 128.0 / I) * (1 - mask_1)
I_new = I + Increment - 128.0
mask_2 = I_new > 0.0
R_new = rhs + (256.0-rhs) * I_new / 128.0
G_new = ghs + (256.0-ghs) * I_new / 128.0
B_new = bhs + (256.0-bhs) * I_new / 128.0
R_new = R_new * mask_2 + (rhs + rhs * I_new/128.0) * (1-mask_2)
G_new = G_new * mask_2 + (ghs + ghs * I_new/128.0) * (1-mask_2)
B_new = B_new * mask_2 + (bhs + bhs * I_new/128.0) * (1-mask_2)
Img_out = img * 1.0
Img_out[:, :, 0] = R_new
Img_out[:, :, 1] = G_new
Img_out[:, :, 2] = B_new
Img_out = Img_out/255.0
# 飽和處理
mask_1 = Img_out < 0
mask_2 = Img_out > 1
Img_out = Img_out * (1-mask_1)
Img_out = Img_out * (1-mask_2) + mask_2
plt.figure()
plt.imshow(img/255.0)
plt.axis('off')
plt.figure(2)
plt.imshow(Img_out)
plt.axis('off')
plt.figure(3)
plt.imshow(I/255.0, plt.cm.gray)
plt.axis('off')
plt.show()
以上就是python 調(diào)整圖片亮度的示例的詳細(xì)內(nèi)容,更多關(guān)于python 調(diào)整圖片亮度的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- python使用PIL給圖片添加文字生成海報(bào)示例
- 如何使用Python進(jìn)行PDF圖片識(shí)別OCR
- python爬蟲(chóng)爬取圖片的簡(jiǎn)單代碼
- python制作微博圖片爬取工具
- python郵件中附加文字、html、圖片、附件實(shí)現(xiàn)方法
- python 使用xlsxwriter循環(huán)向excel中插入數(shù)據(jù)和圖片的操作
- Python基于mediainfo批量重命名圖片文件
- python 實(shí)現(xiàn)圖片修復(fù)(可用于去水?。?/a>
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(dlib版)
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(opencv版)
- 用Python制作音樂(lè)海報(bào)
相關(guān)文章
手把手教你用Python中的Linting提高代碼質(zhì)量
Python是一種不斷發(fā)展的語(yǔ)言,隨著它的演化和擴(kuò)展,可用工具和開(kāi)發(fā)策略的數(shù)量也在增加,近來(lái)流行的一個(gè)過(guò)程是linting—檢查代碼的潛在問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于用Python中Linting提高代碼質(zhì)量的相關(guān)資料,需要的朋友可以參考下2023-01-01
python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作示例
這篇文章主要介紹了python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作,結(jié)合實(shí)例形式詳細(xì)分析了Python修改固定模式字符串原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-12-12
DJango的創(chuàng)建和使用詳解(默認(rèn)數(shù)據(jù)庫(kù)sqlite3)
今天小編就為大家分享一篇DJango的創(chuàng)建和使用詳解(默認(rèn)數(shù)據(jù)庫(kù)sqlite3),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
Python簡(jiǎn)單實(shí)現(xiàn)網(wǎng)頁(yè)內(nèi)容抓取功能示例
這篇文章主要介紹了Python簡(jiǎn)單實(shí)現(xiàn)網(wǎng)頁(yè)內(nèi)容抓取功能,結(jié)合實(shí)例形式分析了Python基于urllib模塊的網(wǎng)頁(yè)請(qǐng)求、內(nèi)容讀取等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
70行Python代碼實(shí)現(xiàn)一個(gè)桌面自動(dòng)翻譯工具
PySimpleGUI是一款很棒的自動(dòng)化輔助模塊,讓你更輕松的實(shí)現(xiàn)日常任務(wù)的自動(dòng)化。本文將利用PySimpleGUI編寫(xiě)一個(gè)桌面自動(dòng)翻譯工具,感興趣的可以了解一下2022-07-07
python3使用print打印帶顏色的字符串代碼實(shí)例
這篇文章主要介紹了python3使用print打印帶顏色的字符串代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08

