Python實現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整
更新時間:2019年06月28日 11:21:32 投稿:mrr
這篇文章主要介紹了Python實現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整 ,需要的朋友可以參考下
本文用 Python 實現(xiàn) PS 圖像調(diào)整中的亮度調(diào)整,具體的算法原理和效果可以參考之前的博客:
http://www.dbjr.com.cn/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 圖像調(diào)整中的亮度調(diào)整 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
您可能感興趣的文章:
相關文章
Numpy中ndim、shape、dtype、astype的用法詳解
這篇文章主要介紹了Numpy中ndim、shape、dtype、astype的用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06Python 實現(xiàn)將數(shù)組/矩陣轉(zhuǎn)換成Image類
今天小編就為大家分享一篇Python 實現(xiàn)將數(shù)組/矩陣轉(zhuǎn)換成Image類,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01Python基于Socket實現(xiàn)的簡單聊天程序示例
這篇文章主要介紹了Python基于Socket實現(xiàn)的簡單聊天程序,結合簡單實例形式分析了Python聊天程序的客戶端與服務器端相關實現(xiàn)技巧,需要的朋友可以參考下2017-08-08