Python實現(xiàn) PS 圖像調整中的亮度調整
本文用 Python 實現(xiàn) PS 圖像調整中的亮度調整,具體的算法原理和效果可以參考之前的博客:
http://m.fzitv.net/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()
總結
以上所述是小編給大家介紹的Python實現(xiàn) PS 圖像調整中的亮度調整 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
相關文章
pycharm 中mark directory as exclude的用法詳解
今天小編就為大家分享一篇pycharm 中mark directory as exclude的用法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
python Pandas如何對數(shù)據(jù)集隨機抽樣
這篇文章主要介紹了python Pandas如何對數(shù)據(jù)集隨機抽樣,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07
Win10 GPU運算環(huán)境搭建(CUDA10.0+Cudnn 7.6.5+pytroch1.2+tensorflow1.
熟悉深度學習的人都知道,深度學習是需要訓練的,本文主要介紹了Win10 GPU運算環(huán)境搭建,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09
Python基于React-Dropzone實現(xiàn)上傳組件的示例代碼
本文主要介紹了在React-Flask框架上開發(fā)上傳組件的技巧。文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08
PySpark與GraphFrames的安裝與使用環(huán)境搭建過程
這篇文章主要介紹了PySpark與GraphFrames的安裝與使用教程,本文通過圖文并茂實例代碼相結合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02
PyCharm提示No Python Interpreter的正確解決辦法
剛學Python時,拿到一個Python項目,想用pycharm打開運行卻報錯了,這篇文章主要給大家介紹了關于PyCharm提示No Python Interpreter的正確解決辦法,需要的朋友可以參考下2023-10-10
python?request要求接口參數(shù)必須是json數(shù)據(jù)的處理方式
這篇文章主要介紹了python?request要求接口參數(shù)必須是json數(shù)據(jù)的處理方式,Reqeusts支持以form表單形式發(fā)送post請求,只需要將請求的參數(shù)構造成一個字典,然后傳給requests.post()的data參數(shù)即可,本文通過實例代碼給大家介紹的非常詳細,需要的朋友參考下吧2022-08-08

