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实现博客文章爬虫示例
Feb 26 Python
Python实现根据指定端口探测服务器/模块部署的方法
Aug 25 Python
对Python3中dict.keys()转换成list类型的方法详解
Feb 03 Python
Python3内置模块之json编解码方法小结【推荐】
Dec 09 Python
python系统指定文件的查找只输出目录下所有文件及文件夹
Jan 19 Python
如何使用PyCharm将代码上传到GitHub上(图文详解)
Apr 27 Python
python能自学吗
Jun 18 Python
matplotlib 多个图像共用一个colorbar的实现示例
Sep 10 Python
Python实现扫码工具的示例代码
Oct 09 Python
解决python 执行shell命令无法获取返回值的问题
Dec 05 Python
python re模块常见用法例举
Mar 01 Python
python学习之panda数据分析核心支持库
May 07 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
日本因肺炎疫情影响,这几部动漫推延播放!
2020/03/03 日漫
xajax写的留言本
2006/11/25 PHP
php5.3 注意事项说明
2013/07/01 PHP
浅析php创建者模式
2014/11/25 PHP
Ajax提交表单时验证码自动验证 php后端验证码检测
2016/07/20 PHP
javascript 播放器 控制
2007/01/22 Javascript
网页防止tab键的使用快速解决方法
2013/11/07 Javascript
JavaScript移除数组内重复元素的方法
2015/03/18 Javascript
jquery实现表单验证并阻止非法提交
2015/07/09 Javascript
JavaScript的History API使搜索引擎抓取AJAX内容
2015/12/07 Javascript
原生JS封装Ajax插件(同域、jsonp跨域)
2016/05/03 Javascript
Jquery和BigFileUpload实现大文件上传及进度条显示
2016/06/27 Javascript
javascript实现瀑布流动态加载图片原理
2016/08/12 Javascript
bootstrap jquery dataTable 异步ajax刷新表格数据的实现方法
2017/02/10 Javascript
关于react-router的几种配置方式详解
2017/07/24 Javascript
Vue利用路由钩子token过期后跳转到登录页的实例
2017/10/26 Javascript
微信小程序遍历Echarts图表实现多个饼图
2019/04/25 Javascript
手写Vue弹窗Modal的实现代码
2019/09/11 Javascript
vue.js 解决v-model让select默认选中不生效的问题
2020/07/28 Javascript
python基础教程之基本内置数据类型介绍
2014/02/20 Python
pandas中Timestamp类用法详解
2017/12/11 Python
查看keras的默认backend实现方式
2020/06/19 Python
Python多分支if语句的使用
2020/09/03 Python
Python confluent kafka客户端配置kerberos认证流程详解
2020/10/12 Python
python中not、and和or的优先级与详细用法介绍
2020/11/03 Python
GIVENCHY纪梵希官方旗舰店:高定彩妆与贵族护肤品
2018/04/16 全球购物
Java如何格式化日期
2012/08/07 面试题
简述安装Slackware Linux系统的过程
2012/01/12 面试题
家长评语大全
2014/01/22 职场文书
在校大学生的职业生涯规划书
2014/03/14 职场文书
学习雷锋倡议书
2014/04/15 职场文书
绿色校园广播稿
2014/10/13 职场文书
高三英语教学计划
2015/01/23 职场文书
校友回访母校寄语
2015/02/26 职场文书
有关花店创业的计划书模板
2019/08/27 职场文书
mysql 如何获取两个集合的交集/差集/并集
2021/06/08 MySQL