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 selenium 父子、兄弟、相邻节点定位方式详解
Sep 15 Python
python如何获取服务器硬件信息
May 11 Python
Python回文字符串及回文数字判定功能示例
Mar 20 Python
Python处理命令行参数模块optpars用法实例分析
May 31 Python
Tensorflow 同时载入多个模型的实例讲解
Jul 27 Python
CentOS 7 安装python3.7.1的方法及注意事项
Nov 01 Python
详解Python装饰器
Mar 25 Python
python字符串替换re.sub()实例解析
Feb 09 Python
python实现拼图小游戏
Feb 22 Python
python PyAUtoGUI库实现自动化控制鼠标键盘
Sep 09 Python
python调用有道智云API实现文件批量翻译
Oct 10 Python
关于python pygame游戏进行声音添加的技巧
Oct 24 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
php中计算程序运行时间的类代码
2012/11/03 PHP
去除php注释和去除空格函数分享
2014/03/13 PHP
Zend Framework基本页面布局分析
2016/03/19 PHP
php遍历解析xml字符串的方法
2016/05/05 PHP
php结合mysql与mysqli扩展处理事务的方法
2016/06/29 PHP
在PHP中输出JS语句以及乱码问题的解决方案
2019/02/13 PHP
Javascript 同时提交多个Web表单的方法
2009/02/19 Javascript
Extjs学习笔记之七 布局
2010/01/08 Javascript
javascript中负数算术右移、逻辑右移的奥秘探索
2013/10/17 Javascript
使用AmplifyJS组件配合JavaScript进行编程的指南
2015/07/28 Javascript
jQuery滚动加载图片实现原理
2015/12/14 Javascript
jQuery模仿京东/天猫商品左侧分类导航菜单效果
2016/06/29 Javascript
微信小程序 简单教程实例详解
2017/01/13 Javascript
Bootstrap面板使用方法
2017/01/16 Javascript
canvas实现十二星座星空图
2017/02/14 Javascript
教你用十行node.js代码读取docx的文本
2017/03/08 Javascript
webpack项目使用eslint建立代码规范实现
2019/05/16 Javascript
小程序实现搜索框功能
2020/03/26 Javascript
解决vue-cli webpack打包开启Gzip 报错问题
2019/07/24 Javascript
将RGB值转换为灰度值的简单算法
2019/10/09 Javascript
vue 使用插槽分发内容操作示例【单个插槽、具名插槽、作用域插槽】
2020/03/06 Javascript
JavaScript装饰者模式原理与用法实例详解
2020/03/09 Javascript
Element Badge标记的使用方法
2020/07/27 Javascript
python输出指定月份日历的方法
2015/04/23 Python
Python range、enumerate和zip函数用法详解
2019/09/11 Python
python web框架Flask实现图形验证码及验证码的动态刷新实例
2019/10/14 Python
Python异步编程之协程任务的调度操作实例分析
2020/02/01 Python
设置jupyter中DataFrame的显示限制方式
2020/04/12 Python
pycharm激活方法到2099年(激活流程)
2020/09/22 Python
Python3读写ini配置文件的示例
2020/11/06 Python
python excel多行合并的方法
2020/12/09 Python
HTML5到底会有什么发展?HTML5的前景展望
2015/07/07 HTML / CSS
微笑面对生活演讲稿
2014/09/23 职场文书
基层党员群众路线教育实践活动个人对照检查材料思想汇报
2014/10/05 职场文书
数学教师个人工作总结
2015/02/06 职场文书
如何利用pygame实现打飞机小游戏
2021/05/30 Python