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模块顶层运行的代码引起的一个Bug
Jul 04 Python
Win10下Python环境搭建与配置教程
Nov 18 Python
Python正则表达式非贪婪、多行匹配功能示例
Aug 08 Python
基于python的字节编译详解
Sep 20 Python
python实现自主查询实时天气
Jun 22 Python
pandas pivot_table() 按日期分多列数据的方法
Nov 16 Python
python使用celery实现异步任务执行的例子
Aug 28 Python
Python Django模板之模板过滤器与自定义模板过滤器示例
Oct 18 Python
python 检查数据中是否有缺失值,删除缺失值的方式
Dec 02 Python
python如何进行矩阵运算
Jun 05 Python
浅谈keras使用中val_acc和acc值不同步的思考
Jun 18 Python
Python爬取你好李焕英豆瓣短评生成词云的示例代码
Feb 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
THINKPHP+JS实现缩放图片式截图的实现
2010/03/07 PHP
php简单获取目录列表的方法
2015/03/24 PHP
php截取指定2个字符之间字符串的方法
2015/04/15 PHP
PHP+MYSQL中文乱码问题
2015/07/01 PHP
PHP与Web页面交互操作实例分析
2020/06/02 PHP
JavaScript 加号(+)运算符号
2009/12/06 Javascript
jquery刷新页面的实现代码(局部及全页面刷新)
2011/07/11 Javascript
基于jquery插件制作左右按钮与标题文字图片切换效果
2013/11/07 Javascript
JQuery中使用Ajax赋值给全局变量失败异常的解决方法
2014/08/18 Javascript
JavaScript 事件对象介绍
2015/04/13 Javascript
JS实现动态表格的添加,修改,删除功能(推荐)
2016/06/15 Javascript
BootStrap Validator使用注意事项(必看篇)
2016/09/28 Javascript
使用vue.js2.0 + ElementUI开发后台管理系统详细教程(一)
2017/01/21 Javascript
利用node.js+mongodb如何搭建一个简单登录注册的功能详解
2017/07/30 Javascript
bootstrap里bootstrap动态加载下拉框的实例讲解
2018/08/10 Javascript
JS加密插件CryptoJS实现的Base64加密示例
2020/08/16 Javascript
NodeJS配置CORS实现过程详解
2020/12/02 NodeJs
Vue仿Bibibili首页的问题
2021/01/21 Vue.js
python集合用法实例分析
2015/05/30 Python
Python2.7下安装Scrapy框架步骤教程
2017/12/22 Python
Flask解决跨域的问题示例代码
2018/02/12 Python
Python 分发包中添加额外文件的方法
2019/08/16 Python
vim自动补全插件YouCompleteMe(YCM)安装过程解析
2019/10/21 Python
解决CSS3的opacity属性带来的层叠顺序问题
2016/05/09 HTML / CSS
欧洲第一的摇滚和金属乐队服装网站:EMP
2017/10/26 全球购物
最畅销的视频游戏享受高达90%的折扣:CDKeys
2020/02/10 全球购物
Myprotein比利时官方网站:欧洲第一运动营养品牌
2020/10/04 全球购物
毕业生个人投资创业计划书
2014/01/04 职场文书
迟到早退检讨书
2014/02/10 职场文书
材料员岗位职责
2014/03/13 职场文书
十佳中学生事迹材料
2014/06/02 职场文书
六一儿童节活动总结
2014/08/27 职场文书
运动会搞笑广播稿
2014/10/14 职场文书
2015年国庆晚会主持词
2015/07/01 职场文书
使用Python+OpenCV进行卡类型及16位卡号数字的OCR功能
2021/08/30 Python
python神经网络 tf.name_scope 和 tf.variable_scope 的区别
2022/05/04 Python