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

http://blog.csdn.net/matrix_space/article/details/22991683

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 图像调整--亮度调整的更多相关文章

  1. Python: PS 图像调整--明度调整

    本文用 Python 实现 PS 图像调整中的明度调整: 我们知道,一般的非线性RGB亮度调整只是在原有R.G.B值基础上增加和减少一定量来实现的,而PS的明度调整原理还得从前面那个公式上去找.我们将 ...

  2. Python: PS 图像调整--饱和度调整

    本文用 Python 实现 PS 图像调整中的饱和度调整算法,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...

  3. Python: PS 图像调整--黑白

    本文用Python 实现 PS 里的图像调整–黑白,PS 里的黑白并不是简单粗暴的将图像转为灰度图,而是做了非常精细的处理,具体的算法原理和效果图可以参考以前的博客: http://blog.csdn ...

  4. Python: PS 图像调整--对比度调整

    本文用 Python 实现 PS 里的图像调整–对比度调整.具体的算法原理如下: (1).nRGB = RGB + (RGB - Threshold) * Contrast / 255 公式中,nRG ...

  5. Python: PS 图像调整--颜色梯度

    本文用 Python 实现 PS 中的色彩图,可以看到颜色的各种渐变,具体的效果可以参考以前的博客: http://blog.csdn.net/matrix_space/article/details ...

  6. PS 图像调整算法——亮度调整

    这个算法是参考自 阿发伯 的博客,在此对 阿发伯 表示感谢, http://blog.csdn.net/maozefa 亮度调整 非线性亮度调整: 对于R,G,B三个通道,每个通道增加相同的增量. 线 ...

  7. PS 图像调整算法——自动对比度 (Auto Contrast)

    PS 给出的定义: Enhance Monochromatic Contrast: Clips all channels identically. This preserves the overall ...

  8. PS 图像调整算法——自动色阶 (Auto Levels)

    PS 给出的定义: Enhance Per Channel Contrast:Maximizes the tonal range in each channel to produce a more d ...

  9. PS 图像调整算法——黑白

    这个算法是参考自 阿发伯 的博客: http://blog.csdn.net/maozefa 黑白调整 Photoshop CS的图像黑白调整功能,是通过对红.黄.绿.青.蓝和洋红等6种颜色的比例调节 ...

随机推荐

  1. 局域网虚拟机端口映射访问apache

    如果我们在虚拟机内搭建好服务器后,希望可以在局域网内的设备上都能访问到这个虚拟服务器,就可以参照以下步骤来操作.其中包括了很多遇到的坑.先说说我的环境是 宿主机:windows 8.1 虚拟机:vmw ...

  2. zoj 2835 Magic Square(set)

    Magic Square Time Limit: 2 Seconds      Memory Limit: 65536 KB In recreational mathematics, a magic ...

  3. php5.5编译安装

    系统环境:centos6.5PHP包:5.5.15https://wiki.swoole.com/wiki/page/177.html下载 PHP 源码包wget http://cn2.php.net ...

  4. 从零开始写STL—set/map

    这一部分只要把搜索树中暴露的接口封装一下,做一些改动. set源码剖析 template<typename T> class set { public: typedef T key_typ ...

  5. hdu 4971

    记忆花搜索   dp #include <cstdio> #include <cstdlib> #include <cmath> #include <set& ...

  6. [Bzoj1015][JSOI2008]星球大战starwar(并查集)(离线处理)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 6849  Solved: 3204[Submit ...

  7. 2017多校Round4(hdu6067~hdu6079)

    补题进度:10/13 1001 待填坑 1002(kmp+递推) 题意: 有长度为n(<=50000)的字符串S和长度为m(m<=100)的字符串T,有k(k<=50000)组询问, ...

  8. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1054 这个错误困扰了我一个下午  插入数据总是错误 ...

  9. java多线程编程01---------基本概念

    一. java多线程编程基本概念--------基本概念 java多线程可以说是java基础中相对较难的部分,尤其是对于小白,次一系列文章的将会对多线程编程及其原理进行介绍,希望对正在多线程中碰壁的小 ...

  10. 过滤器链chain.doFilter(request,response)含义

    过滤器的生命周期一般都要经过下面三个阶段: 初始化 当容器第一次加载该过滤器时,init() 方法将被调用.该类在这个方法中包含了一个指向 Filter Config 对象的引用. 过滤 过滤器的大多 ...