本文用 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. functools内置装饰器

    def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): def ...

  2. NYOJ-481平衡字符串

    平衡字符串 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 给你一定长度的字符串.字符串中只包含26个小写字母,首先我们把字母a-z分为2堆(a--m)和(n--z),判 ...

  3. android去除标题栏和状态栏(全屏)

    转--http://www.eoeandroid.com/thread-66555-1-1.html 在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方 ...

  4. POJ 3615 Cow Hurdles

    http://poj.org/problem?id=3615 floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边 那么输入的时候可以直接把dist[i][j] 当作i j ...

  5. centos、mac的grafana安装和简单使用

    1.安装: 参考官方文档安装说明:https://grafana.com/grafana/download Redhat & Centos(64 Bit): wget https://s3-u ...

  6. Dialog集合

    点击查看原文 demo下载地址http://download.csdn.net/detail/metis100/8498401 安卓开发一年.開始想整理些资料成库,以备日后高速开发. 第一天,整理了经 ...

  7. Meteor核心API

    在本教程中,我们将介绍学习Meteor核心API. 如果你想限制代码只在服务器或客户端可以使用下面的代码运行 - meteorApp.js if (Meteor.isClient) { // Code ...

  8. [Javascript] Link to Other Objects through the JavaScript Prototype Chain

    Objects have the ability to use data and methods that other objects contain, as long as it lives on ...

  9. [React] PureComponent in React

    In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...

  10. Linux性能诊断工具

    vmstat:虚拟内存状况 –swpd   free  buff  cache   si  so   in   cs 參考:http://www.cnblogs.com/ggjucheng/archi ...