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

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

import matplotlib.pyplot as plt
from skimage import io file_name = 'D:/Visual Effects/PS Algorithm/4.jpg'
img=io.imread(file_name) img = img * 1.0
img_out = img * 1.0 # -1 ~ 1
Increment = 0.5 img_min = img.min(axis=2)
img_max = img.max(axis=2) Delta = (img_max - img_min) / 255.0
value = (img_max + img_min) / 255.0
L = value/2.0 mask_1 = L < 0.5 s1 = Delta/(value + 0.001)
s2 = Delta/(2 - value + 0.001)
s = s1 * mask_1 + s2 * (1 - mask_1) if Increment >= 0 :
temp = Increment + s
mask_2 = temp > 1
alpha_1 = s
alpha_2 = s * 0 + 1 - Increment
alpha = alpha_1 * mask_2 + alpha_2 * (1 - mask_2)
alpha = 1/(alpha + 0.001) -1
img_out[:, :, 0] = img[:, :, 0] + (img[:, :, 0] - L * 255.0) * alpha
img_out[:, :, 1] = img[:, :, 1] + (img[:, :, 1] - L * 255.0) * alpha
img_out[:, :, 2] = img[:, :, 2] + (img[:, :, 2] - L * 255.0) * alpha else:
alpha = Increment
img_out[:, :, 0] = L * 255.0 + (img[:, :, 0] - L * 255.0) * (1 + alpha)
img_out[:, :, 1] = L * 255.0 + (img[:, :, 1] - L * 255.0) * (1 + alpha)
img_out[:, :, 2] = L * 255.0 + (img[:, :, 2] - L * 255.0) * (1 + alpha) 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.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/details/2 ...

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

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

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

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

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

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

  6. Python: PS 图像特效 — 模糊玻璃

    今天介绍一种基于高斯滤波和邻域随机采样,生成一种毛玻璃的图像特效,简单来说,就是先对图像做高斯滤波模糊,然后对模糊后的图像,通过对邻域的随机采样来赋予当前的像素点,这样,生成的图像有有一定的随机扰动和 ...

  7. Python: PS 图像特效 — 抽象画风

    今天介绍一种基于图像分割和color map 随机采样生成一种抽象画风的图像特效,简单来说,就是先生成一张 color map 图,颜色是渐变的,然后针对要处理的图像,进行分割,这里用的是 SLIC ...

  8. PS 图像调整算法——饱和度调整

    算法参考自 阿发伯 的博客. http://blog.csdn.net/maozefa 饱和度调整 图像的饱和度调整有很多方法,最简单的就是判断每个象素的R.G.B值是否大于或小于128,大于加上调整 ...

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

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

随机推荐

  1. iOS -- MBProgressHUB

    高级: http://www.jianshu.com/p/485b8d75ccd4 //只有小菊花 - (void)indeterminateExample { // Show the HUD on ...

  2. Window10下Apache2.4的安装和运行

    以前用Python运行的Web框架都是要运行在Linux下,加上WSGI服务器,比如Gunicorn+Flask,后来了解到了Apache,看看能不能基于Apache这个Web服务器下给python提 ...

  3. vue doubleclick 鼠标双击事件

    Vue-dblclick事件(此外事件还有mouseover,mouseout,click,mousdown...): v-on:dblclick="函数" v-on:click/ ...

  4. linux下的C语言开发(网络编程)

    http://blog.csdn.net/feixiaoxing/article/details/7259675 [ 声明:版权所有,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing ...

  5. java线程中Exchanger使用

    有时我们须要对元素进行配对和交换线程的同步点,使用exchange方法 返回其伙伴的对象,这时我们就须要使用线程类中的Exchanger类了, 我通过一个实例 来简单说明一下他的用法及其作用: imp ...

  6. 转:Json 语法 格式

    转自: http://www.cnblogs.com/chencidi/archive/2011/03/24/1993450.html 评注: json 官网如下: http://json.org/j ...

  7. django 实现下载功能

    from django.http import FileResponse def download(request): if..... file=open([path],'rb') response= ...

  8. Office 顿号怎么输

    中文状态下回车上面一个按键就是  

  9. PS 如何使用钢笔工具

    1.钢笔工具属于矢量绘图工具,其优点是可以勾画平滑的曲线,在缩放或者变形之后仍能保持平滑效果. 2.钢笔工具画出来的矢量图形称为路径,路径是矢量的路径允许是不封闭的开放状,如果把起点与终点重合绘制就可 ...

  10. SD卡操作相关的工具SDCardUtils

    SD卡操作相关的工具 package com.flyou.utils; import java.io.File; import android.os.Environment; import andro ...