Python實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整
本文用 Python 實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整,具體的算法原理和效果可以參考之前的博客:
http://www.dhdzp.com/article/164191.htm
import matplotlib.pyplot as plt
from skimage import io
file_name='D:/Image Processing/PS Algorithm/4.jpg';
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()
總結(jié)
以上所述是小編給大家介紹的Python實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整 ,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- python中PS 圖像調(diào)整算法原理之亮度調(diào)整
- Python實(shí)現(xiàn)PS圖像調(diào)整之對(duì)比度調(diào)整功能示例
- Python實(shí)現(xiàn)PS圖像調(diào)整黑白效果示例
- Python實(shí)現(xiàn)PS圖像調(diào)整顏色梯度效果示例
- Python實(shí)現(xiàn)PS圖像明亮度調(diào)整效果示例
- python 設(shè)置輸出圖像的像素大小方法
- python隨機(jī)在一張圖像上截取任意大小圖片的方法
- Python繪制并保存指定大小圖像的方法
- 用python 批量更改圖像尺寸到統(tǒng)一大小的方法
- 如何使用Python調(diào)整圖像大小
相關(guān)文章
pycharm 中mark directory as exclude的用法詳解
今天小編就為大家分享一篇pycharm 中mark directory as exclude的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python設(shè)計(jì)模式中的創(chuàng)建型工廠模式
這篇文章主要介紹了Python設(shè)計(jì)模式中的創(chuàng)建型工廠模式,工廠模式即Factory?Pattern,是提供創(chuàng)建對(duì)象的最佳方式,下文小編介紹Python工廠模式的相關(guān)資料,需要的朋友可以參考一下2022-02-02
python Pandas如何對(duì)數(shù)據(jù)集隨機(jī)抽樣
這篇文章主要介紹了python Pandas如何對(duì)數(shù)據(jù)集隨機(jī)抽樣,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Win10 GPU運(yùn)算環(huán)境搭建(CUDA10.0+Cudnn 7.6.5+pytroch1.2+tensorflow1.
熟悉深度學(xué)習(xí)的人都知道,深度學(xué)習(xí)是需要訓(xùn)練的,本文主要介紹了Win10 GPU運(yùn)算環(huán)境搭建,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Python基于React-Dropzone實(shí)現(xiàn)上傳組件的示例代碼
本文主要介紹了在React-Flask框架上開發(fā)上傳組件的技巧。文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
PySpark與GraphFrames的安裝與使用環(huán)境搭建過程
這篇文章主要介紹了PySpark與GraphFrames的安裝與使用教程,本文通過圖文并茂實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02
PyCharm提示No Python Interpreter的正確解決辦法
剛學(xué)Python時(shí),拿到一個(gè)Python項(xiàng)目,想用pycharm打開運(yùn)行卻報(bào)錯(cuò)了,這篇文章主要給大家介紹了關(guān)于PyCharm提示No Python Interpreter的正確解決辦法,需要的朋友可以參考下2023-10-10
python?request要求接口參數(shù)必須是json數(shù)據(jù)的處理方式
這篇文章主要介紹了python?request要求接口參數(shù)必須是json數(shù)據(jù)的處理方式,Reqeusts支持以form表單形式發(fā)送post請(qǐng)求,只需要將請(qǐng)求的參數(shù)構(gòu)造成一個(gè)字典,然后傳給requests.post()的data參數(shù)即可,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-08-08

