python 調(diào)整圖片亮度的示例
更新時間:2020年12月03日 11:20:12 作者:未雨愁眸
這篇文章主要介紹了python 調(diào)整圖片亮度的示例代碼,幫助大家更好的利用python處理圖片,感興趣的朋友可以了解下
實現(xiàn)效果

實現(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)整圖片亮度的示例的詳細內(nèi)容,更多關(guān)于python 調(diào)整圖片亮度的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:
相關(guān)文章
手把手教你用Python中的Linting提高代碼質(zhì)量
Python是一種不斷發(fā)展的語言,隨著它的演化和擴展,可用工具和開發(fā)策略的數(shù)量也在增加,近來流行的一個過程是linting—檢查代碼的潛在問題,下面這篇文章主要給大家介紹了關(guān)于用Python中Linting提高代碼質(zhì)量的相關(guān)資料,需要的朋友可以參考下2023-01-01
python實現(xiàn)修改固定模式的字符串內(nèi)容操作示例
這篇文章主要介紹了python實現(xiàn)修改固定模式的字符串內(nèi)容操作,結(jié)合實例形式詳細分析了Python修改固定模式字符串原理、實現(xiàn)方法及相關(guān)操作注意事項,需要的朋友可以參考下2019-12-12
DJango的創(chuàng)建和使用詳解(默認數(shù)據(jù)庫sqlite3)
今天小編就為大家分享一篇DJango的創(chuàng)建和使用詳解(默認數(shù)據(jù)庫sqlite3),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
Python簡單實現(xiàn)網(wǎng)頁內(nèi)容抓取功能示例
這篇文章主要介紹了Python簡單實現(xiàn)網(wǎng)頁內(nèi)容抓取功能,結(jié)合實例形式分析了Python基于urllib模塊的網(wǎng)頁請求、內(nèi)容讀取等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06

