溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整

發(fā)布時(shí)間:2020-09-08 14:26:45 來(lái)源:腳本之家 閱讀:133 作者:mrr 欄目:開(kāi)發(fā)技術(shù)

本文用 Python 實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整,具體的算法原理和效果可以參考之前的博客:

https://www.jb51.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()

總結(jié)

以上所述是小編給大家介紹的Python實(shí)現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整 ,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI