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中asyncore异步模块的用法及实现httpclient的实例
Jun 28 Python
Python用Pillow(PIL)进行简单的图像操作方法
Jul 07 Python
Python3获取电脑IP、主机名、Mac地址的方法示例
Apr 11 Python
Python openpyxl读取单元格字体颜色过程解析
Sep 03 Python
利用python读取YUV文件 转RGB 8bit/10bit通用
Dec 09 Python
python解析xml文件方式(解析、更新、写入)
Mar 05 Python
如何通过Python3和ssl实现加密通信功能
May 09 Python
python中id函数运行方式
Jul 03 Python
django rest framework 过滤时间操作
Jul 12 Python
python 使用递归的方式实现语义图片分割功能
Jul 16 Python
Python eval函数介绍及用法
Nov 09 Python
python matplotlib工具栏源码探析三之添加、删除自定义工具项的案例详解
Feb 25 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
cache_lite试用
2007/02/14 PHP
七款最流行的PHP本地服务器分享
2013/02/19 PHP
php文件缓存方法总结
2016/03/16 PHP
PHP通过加锁实现并发情况下抢码功能
2016/08/10 PHP
php 浮点数比较方法详解
2017/05/05 PHP
PHP自定义错误处理的方法分析
2018/12/19 PHP
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
2020/03/18 PHP
js 面向对象的技术创建高级 Web 应用程序
2010/02/25 Javascript
兼容Firefox的Javascript XSLT 处理XML文件
2014/12/31 Javascript
JavaScript中Math.SQRT2属性的使用详解
2015/06/14 Javascript
详解JS面向对象编程
2016/01/24 Javascript
webpack写jquery插件的环境配置
2017/12/21 jQuery
Vue.js添加组件操作示例
2018/06/13 Javascript
玩转vue的slot内容分发
2018/09/22 Javascript
亲自动手实现vue日历控件
2019/06/26 Javascript
JavaScript常用工具函数大全
2020/05/06 Javascript
原生JS实现无缝轮播图片
2020/06/24 Javascript
解决基于 keep-alive 的后台多级路由缓存问题
2020/12/23 Javascript
js制作提示框插件
2020/12/24 Javascript
python 合并文件的具体实例
2013/08/08 Python
python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)
2013/12/08 Python
使用Python3中的gettext模块翻译Python源码以支持多语言
2015/03/31 Python
Python入门之modf()方法的使用
2015/05/15 Python
定制FileField中的上传文件名称实例
2017/08/23 Python
python实现随机加减法生成器
2020/02/24 Python
Django框架获取form表单数据方式总结
2020/04/22 Python
Django实现文章详情页面跳转代码实例
2020/09/16 Python
Python尾递归优化实现代码及原理详解
2020/10/09 Python
PyTorch预训练Bert模型的示例
2020/11/17 Python
微软美国官方网站:Microsoft美国
2018/05/10 全球购物
Under Armour瑞典官方网站:美国高端运动科技品牌
2018/11/21 全球购物
教师纪念9.18事件演讲稿范文
2014/09/14 职场文书
贷款工资证明范本
2015/06/12 职场文书
2015教师节通讯稿
2015/07/20 职场文书
2016感恩父亲节主题广播稿
2015/12/18 职场文书
Django对接elasticsearch实现全文检索的示例代码
2021/08/02 Python