本篇文章为大家展示了利用python如何调整图片的亮度,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
实现代码
import matplotlib.pyplot as plt from skimage import io file_name='D:/2020121173119242.png' 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如何调整图片的亮度,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。