python 调整图片亮度的示例

作者:未雨愁眸 时间:2021-06-05 22:52:01 

实现效果

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()

来源:https://www.cnblogs.com/mtcnn/category/1269166.html?page=1

标签:python,图片,亮度
0
投稿

猜你喜欢

  • WEB标准与XHTML 1.0 Transitional等文档类型介绍

    2007-10-20 21:18:00
  • python使用turtle库绘制奥运五环

    2021-06-21 04:22:44
  • java JSP开发之Spring中Bean的使用

    2023-06-16 07:35:08
  • asp datediff 时间相减

    2011-03-25 10:34:00
  • asp 在线备份与恢复sqlserver数据库的代码

    2011-03-06 11:14:00
  • 中国,美国,英国3国时间同步动态显示js代码

    2007-09-27 20:34:00
  • python删除文件、清空目录的实现方法

    2021-06-02 02:53:06
  • python 的 openpyxl模块 读取 Excel文件的方法

    2023-02-23 14:41:56
  • MySQL聚焦Web 2.0可扩展性

    2012-01-05 19:02:19
  • 小议JavaScript泛式框架架构的逻辑形式

    2010-07-02 12:55:00
  • 推荐给大家看的设计书

    2009-02-23 12:17:00
  • jQuerify书签

    2008-06-16 12:16:00
  • 详解Python图像处理库Pillow常用使用方法

    2022-07-17 11:04:53
  • 分享Pycharm中一些不为人知的技巧

    2023-10-04 04:52:54
  • python3+PyQt5使用数据库窗口视图

    2023-03-08 10:44:26
  • python爬虫 urllib模块发起post请求过程解析

    2022-02-07 22:52:53
  • python Matplotlib模块的使用

    2022-12-26 21:18:37
  • asp如何对Access数据库进行压缩?

    2009-11-19 21:20:00
  • Python+django实现文件下载

    2022-03-10 15:54:16
  • 一些不错的js函数ajax

    2023-08-25 14:01:38
  • asp之家 网络编程 m.aspxhome.com