Python实现 PS 图像调整中的亮度调整


Posted in Python onJune 28, 2019

本文用 Python 实现 PS 图像调整中的亮度调整,具体的算法原理和效果可以参考之前的博客:

import matplotlib.pyplot as plt
from skimage import io
file_name='D:/Image Processing/PS Algorithm/4.jpg';
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实现 PS 图像调整中的亮度调整 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

Python 相关文章推荐
Python中的类与对象之描述符详解
Mar 27 Python
python简单实现旋转图片的方法
May 30 Python
python获取mp3文件信息的方法
Jun 15 Python
Python MD5加密实例详解
Aug 02 Python
简单了解python模块概念
Jan 11 Python
python调用xlsxwriter创建xlsx的方法
May 03 Python
解决Django一个表单对应多个按钮的问题
Jul 18 Python
python原类、类的创建过程与方法详解
Jul 19 Python
Python单元测试工具doctest和unittest使用解析
Sep 02 Python
详解numpy矩阵的创建与数据类型
Oct 18 Python
python-地图可视化组件folium的操作
Dec 14 Python
Python命令行参数argv和argparse该如何使用
Feb 08 Python
Python绘图Matplotlib之坐标轴及刻度总结
Jun 28 #Python
python启动应用程序和终止应用程序的方法
Jun 28 #Python
简单了解python高阶函数map/reduce
Jun 28 #Python
安装好Pycharm后如何配置Python解释器简易教程
Jun 28 #Python
关于 Python opencv 使用中的 ValueError: too many values to unpack
Jun 28 #Python
python识别图像并提取文字的实现方法
Jun 28 #Python
python3射线法判断点是否在多边形内
Jun 28 #Python
You might like
SONY ICF-SW55的电路分析
2021/03/02 无线电
PHP 设计模式之观察者模式介绍
2012/02/22 PHP
分享一下贝贝成长进度的php代码
2012/09/14 PHP
php源码 fsockopen获取网页内容实例详解
2016/09/24 PHP
tp5(thinkPHP5)框架连接数据库的方法示例
2018/12/24 PHP
JavaScript实现的经典文件树菜单效果
2015/09/08 Javascript
自动完成的搜索框javascript实现
2016/02/26 Javascript
js获取form表单所有数据的简单方法
2016/08/18 Javascript
jQuery 的 ready()的纯js替代方法
2016/11/20 Javascript
javascript实现文字无缝滚动
2016/12/27 Javascript
浅谈sass在vue注意的地方
2017/08/10 Javascript
详解Vue微信公众号开发踩坑全记录
2017/08/21 Javascript
vue2.0移除或更改的一些东西(移除index key)
2017/08/28 Javascript
小程序自定义组件实现城市选择功能
2018/07/18 Javascript
详解Vue.js自定义tipOnce指令用法实例
2018/12/19 Javascript
es6数据变更同步到视图层的方法
2019/03/04 Javascript
浅谈KOA2 Restful方式路由初探
2019/03/14 Javascript
移动端手指操控左右滑动的菜单
2019/09/08 Javascript
python实现根据文件关键字进行切分为多个文件的示例
2018/12/10 Python
Python计算指定日期是今年的第几天(三种方法)
2020/03/26 Python
python+adb+monkey实现Rom稳定性测试详解
2020/04/23 Python
css3 pointer-events 介绍详解
2017/09/18 HTML / CSS
使用javascript和HTML5 Canvas画的四渐变色播放按钮效果
2014/04/10 HTML / CSS
阳光体育:Sunny Sports(购买露营和远足设备)
2018/08/07 全球购物
什么是Smarty变量操作符?如何使用Smarty变量操作符
2014/07/18 面试题
教师年终个人自我评价
2013/10/04 职场文书
应届毕业生的自我鉴定
2013/11/13 职场文书
火车来了教学反思
2014/02/11 职场文书
公司司机岗位职责范本
2014/03/03 职场文书
辩论赛主持词
2014/03/18 职场文书
经贸专业毕业生求职信范文
2014/05/01 职场文书
防沙治沙典型材料
2014/05/07 职场文书
学生安全承诺书
2014/05/22 职场文书
英文商务邀请函范文
2015/01/31 职场文书
spring cloud gateway中如何读取请求参数
2021/07/15 Java/Android
24年收藏2000多部退役军用电台
2022/02/18 无线电