python 调整图片亮度的示例


Posted in Python onDecember 03, 2020

实现效果

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 调整图片亮度的示例的详细内容,更多关于python 调整图片亮度的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
浅谈python numpy中nonzero()的用法
Apr 02 Python
Python使用 Beanstalkd 做异步任务处理的方法
Apr 24 Python
Python基于lxml模块解析html获取页面内所有叶子节点xpath路径功能示例
May 16 Python
python实现自动发送报警监控邮件
Jun 21 Python
python多行字符串拼接使用小括号的方法
Mar 19 Python
对python中dict和json的区别详解
Dec 18 Python
python 调用有道api接口的方法
Jan 03 Python
Python查找最长不包含重复字符的子字符串算法示例
Feb 13 Python
详解爬虫被封的问题
Apr 23 Python
Python Pandas数据结构简单介绍
Jul 03 Python
基于python及pytorch中乘法的使用详解
Dec 27 Python
基于Python的自媒体小助手---登录页面的实现代码
Jun 29 Python
Python 实现PS滤镜的旋涡特效
Dec 03 #Python
Python 实现PS滤镜中的径向模糊特效
Dec 03 #Python
python字符串拼接+和join的区别详解
Dec 03 #Python
python二维图制作的实例代码
Dec 03 #Python
python 使用paramiko模块进行封装,远程操作linux主机的示例代码
Dec 03 #Python
Python 按比例获取样本数据或执行任务的实现代码
Dec 03 #Python
用 Django 开发一个 Python Web API的方法步骤
Dec 03 #Python
You might like
PHP对MongoDB[NoSQL]数据库的操作
2013/03/01 PHP
PHP中的数组处理函数实例总结
2016/01/09 PHP
Smarty简单生成表单元素的方法示例
2016/05/23 PHP
详细解读php的命名空间(二)
2018/02/21 PHP
TNC vs IO BO3 第一场2.13
2021/03/10 DOTA
为javascript添加String.Format方法
2020/08/11 Javascript
window.ActiveXObject使用说明
2010/11/08 Javascript
jquery中map函数与each函数的区别实例介绍
2014/06/23 Javascript
jquery实现表单验证简单实例演示
2015/11/23 Javascript
用canvas 实现个图片三角化(LOW POLY)效果
2016/02/18 Javascript
Bootstrap媒体对象的实现
2016/05/01 Javascript
使用JQuery实现图片轮播效果的实例(推荐)
2017/10/24 jQuery
Vue2.0 http请求以及loading展示实例
2018/03/06 Javascript
webpack 从指定入口文件中提取公共文件的方法
2018/11/13 Javascript
浅谈vue中关于checkbox数据绑定v-model指令的个人理解
2018/11/14 Javascript
其实你可以少写点if else与switch(推荐)
2019/01/10 Javascript
谈谈JavaScript中super(props)的重要性
2019/02/12 Javascript
vue-froala-wysiwyg 富文本编辑器功能
2019/09/19 Javascript
JS实现旋转木马轮播图
2020/01/01 Javascript
[47:18]完美世界DOTA2联赛循环赛 IO vs FTD BO2第一场 11.05
2020/11/06 DOTA
python re正则表达式模块(Regular Expression)
2014/07/16 Python
Python中optionParser模块的使用方法实例教程
2014/08/29 Python
Python配置文件解析模块ConfigParser使用实例
2015/04/13 Python
教大家使用Python SqlAlchemy
2016/02/12 Python
详解supervisor使用教程
2017/11/21 Python
对Pytorch中nn.ModuleList 和 nn.Sequential详解
2019/08/18 Python
在OpenCV里使用特征匹配和单映射变换的代码详解
2019/10/23 Python
pygame实现非图片按钮效果
2019/10/29 Python
tensorflow模型继续训练 fineturn实例
2020/01/21 Python
解决Django部署设置Debug=False时xadmin后台管理系统样式丢失
2020/04/07 Python
canvas学习笔记之绘制简单路径
2019/01/28 HTML / CSS
肯尼亚网上商城:Kilimall
2016/08/20 全球购物
Coach澳大利亚官方网站:美国著名时尚奢侈品牌
2017/05/24 全球购物
俄罗斯连接商品和买家的在线平台:goods.ru
2020/11/30 全球购物
Golang实现AES对称加密的过程详解
2021/05/20 Golang
浅谈MySQL中的六种日志
2022/03/23 MySQL