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统计文本文件内单词数量的方法
May 30 Python
21行Python代码实现拼写检查器
Jan 25 Python
详解Python的数据库操作(pymysql)
Apr 04 Python
Python3模拟curl发送post请求操作示例
May 03 Python
利用PyCharm Profile分析异步爬虫效率详解
May 08 Python
django获取from表单multiple-select的value和id的方法
Jul 19 Python
Windows10下 python3.7 安装 facenet的教程
Sep 10 Python
在python中利用pycharm自定义代码块教程(三步搞定)
Apr 15 Python
python安装和pycharm环境搭建设置方法
May 27 Python
Python如何爬取qq音乐歌词到本地
Jun 01 Python
Python Mock模块原理及使用方法详解
Jul 07 Python
Django中日期时间型字段进行年月日时分秒分组统计
Nov 27 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
ThinkPHP里用U方法调用js文件实例
2015/06/18 PHP
PHP实现添加购物车功能
2017/03/06 PHP
让你的PHP,APACHE,NGINX支持大文件上传
2021/03/09 PHP
javascript 关于# 和 void的区别分析
2009/10/26 Javascript
ModelDialog JavaScript模态对话框类代码
2011/04/17 Javascript
Javascript 学习笔记之 对象篇(二) : 原型对象
2014/06/24 Javascript
ECMAScript5(ES5)中bind方法使用小结
2015/05/07 Javascript
微信小程序 Windows2008 R2服务器配置TLS1.2方法
2016/12/05 Javascript
js 文字超出长度用省略号代替,鼠标悬停并以悬浮框显示实例
2016/12/06 Javascript
详解基于angular路由的requireJs按需加载js
2017/01/20 Javascript
jQuery中DOM节点的删除方法总结(超全面)
2017/01/22 Javascript
express+vue+mongodb+session 实现注册登录功能
2018/12/06 Javascript
jquery实现拖拽小方块效果
2020/12/10 jQuery
Python三元运算实现方法
2015/01/12 Python
python实现逆波兰计算表达式实例详解
2015/05/06 Python
python创建一个最简单http webserver服务器的方法
2015/05/08 Python
python如何实现远程控制电脑(结合微信)
2015/12/21 Python
python访问mysql数据库的实现方法(2则示例)
2016/01/06 Python
Python常用知识点汇总
2016/05/08 Python
分享python数据统计的一些小技巧
2016/07/21 Python
Python与R语言的简要对比
2017/11/14 Python
python3.6 实现AES加密的示例(pyCryptodome)
2018/01/10 Python
Python开发之pip安装及使用方法详解
2020/02/21 Python
Python logging模块写入中文出现乱码
2020/05/21 Python
python学习笔记之多进程
2020/08/06 Python
英国户外玩具儿童游乐设备网站:TP Toys(蹦床、攀爬框架、秋千、滑梯和游戏屋)
2018/04/09 全球购物
请编程遍历页面上所有 TextBox 控件并给它赋值为 string.Empty
2015/12/03 面试题
linux面试题参考答案(9)
2015/01/07 面试题
什么是GWT的Module
2013/01/20 面试题
七一党建活动方案
2014/01/28 职场文书
师德师风的心得体会
2014/09/02 职场文书
2015年政教主任工作总结
2015/07/23 职场文书
2016教师校本研修心得体会
2016/01/08 职场文书
ORM模型框架操作mysql数据库的方法
2021/07/25 MySQL
bootstrapv4轮播图去除两侧阴影及线框的方法
2022/02/15 HTML / CSS
Python简易开发之制作计算器
2022/04/28 Python