python 調(diào)整圖片亮度的示例
實(shí)現(xiàn)效果
實(shí)現(xiàn)代碼
import matplotlib.pyplot as pltfrom skimage import iofile_name=’D:/2020121173119242.png’img=io.imread(file_name)Increment = -10.0img = img * 1.0 I = (img[:, :, 0] + img[:, :, 1] + img[:, :, 2])/3.0 + 0.001mask_1 = I > 128.0r = 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.0mask_2 = I_new > 0.0R_new = rhs + (256.0-rhs) * I_new / 128.0G_new = ghs + (256.0-ghs) * I_new / 128.0B_new = bhs + (256.0-bhs) * I_new / 128.0R_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.0Img_out[:, :, 0] = R_newImg_out[:, :, 1] = G_newImg_out[:, :, 2] = B_newImg_out = Img_out/255.0# 飽和處理mask_1 = Img_out < 0 mask_2 = Img_out > 1Img_out = Img_out * (1-mask_1)Img_out = Img_out * (1-mask_2) + mask_2plt.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)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. vue-electron中修改表格內(nèi)容并修改樣式2. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法3. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式4. 微信小程序?qū)崿F(xiàn)商品分類頁(yè)過(guò)程結(jié)束5. 推薦一個(gè)好看Table表格的css樣式代碼詳解6. ASP常用日期格式化函數(shù) FormatDate()7. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解8. ASP新手必備的基礎(chǔ)知識(shí)9. HTML中的XML數(shù)據(jù)島記錄編輯與添加10. 不使用XMLHttpRequest對(duì)象實(shí)現(xiàn)Ajax效果的方法小結(jié)
