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爬蟲爬取圖片的簡(jiǎn)單代碼
- python制作微博圖片爬取工具
- python郵件中附加文字、html、圖片、附件實(shí)現(xiàn)方法
- python 使用xlsxwriter循環(huán)向excel中插入數(shù)據(jù)和圖片的操作
- Python基于mediainfo批量重命名圖片文件
- python 實(shí)現(xiàn)圖片修復(fù)(可用于去水印)
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(dlib版)
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(opencv版)
- 用Python制作音樂海報(bào)
相關(guān)文章
深度理解Python中Class類、Object類、Type元類
本文主要介紹了深度理解Python中Class類、Object類、Type元類,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06淺談pandas關(guān)于查看庫(kù)或依賴庫(kù)版本的API原理
本文主要介紹了淺談pandas關(guān)于查看庫(kù)或依賴庫(kù)版本的API原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06關(guān)于Django框架的關(guān)系模型序列化和一對(duì)多關(guān)系中的序列化解析
序列化的意思是把字典的形式轉(zhuǎn)化成Json格式。當(dāng)我們展示數(shù)據(jù)的時(shí)候需要使用,反序列化的話,就是Json轉(zhuǎn)成字典形式,存儲(chǔ)數(shù)據(jù)時(shí)候使用,需要的朋友可以參考下2023-05-05python動(dòng)態(tài)文本進(jìn)度條的實(shí)例代碼
這篇文章主要介紹了python動(dòng)態(tài)文本進(jìn)度條的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01Python面向?qū)ο蟪绦蛟O(shè)計(jì)類的多態(tài)用法詳解
這篇文章主要介紹了Python面向?qū)ο蟪绦蛟O(shè)計(jì)類的多態(tài)用法,結(jié)合實(shí)例形式詳細(xì)分析了Python面向?qū)ο蟪绦蛟O(shè)計(jì)中類的多態(tài)概念、原理、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-04-04使用python實(shí)現(xiàn)excel的Vlookup功能
這篇文章主要介紹了使用python實(shí)現(xiàn)excel的Vlookup功能,當(dāng)我們想要查找的數(shù)據(jù)量較大時(shí),這時(shí)則有請(qǐng)我們的主角VLookup函數(shù)出場(chǎng),那么如何用python實(shí)現(xiàn)VLookup呢,需要的朋友可以參考下2023-04-04詳解Python如何使用Self類型實(shí)現(xiàn)返回類的實(shí)例對(duì)象
在 Python 中,類方法通常會(huì)返回類的實(shí)例對(duì)象,本文將詳細(xì)介紹如何在 Python 中使用 Self 類型來(lái)返回類的實(shí)例對(duì)象,并提供豐富的示例代碼幫助更好地理解,快跟隨小編一起學(xué)習(xí)起來(lái)吧2024-02-02Django框架的使用教程路由請(qǐng)求響應(yīng)的方法
這篇文章主要介紹了Django框架的使用教程路由請(qǐng)求響應(yīng)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07