Python: PS 图像调整--黑白
本文用Python 实现 PS 里的图像调整–黑白,PS 里的黑白并不是简单粗暴的将图像转为灰度图,而是做了非常精细的处理,具体的算法原理和效果图可以参考以前的博客:
http://blog.csdn.net/matrix_space/article/details/22992833
比起之前的程序,对代码进行了优化,完全用矩阵运算代替了 for 循环,运算效率提升了很多。具体的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
file_name='D:/Image Processing/PS Algorithm/4.jpg';
img=io.imread(file_name)
img = img * 1.0
Color_ratio = np.zeros(6)
Color_ratio[0]=0.4; # Red
Color_ratio[1]=0.6; # Yellow
Color_ratio[2]=0.4; # Green
Color_ratio[3]=0.6; # Cyan
Color_ratio[4]=0.2; # Blue
Color_ratio[5]=0.8; # Magenta
max_val = img.max(axis = 2)
min_val = img.min(axis = 2)
sum_val = img.sum(axis = 2)
mid_val = sum_val - max_val - min_val
mask_r = (img[:, :, 0] - min_val - 0.01) > 0
mask_r = 1 - mask_r
mask_g = (img[:, :, 1] - min_val - 0.01) > 0
mask_g = 1 - mask_g
mask_b = (img[:, :, 2] - min_val - 0.01) > 0
mask_b = 1 - mask_b
ratio_max_mid = mask_r * Color_ratio[3] + mask_g * Color_ratio[5] + mask_b * Color_ratio[1]
mask_r = (img[:, :, 0] - max_val + 0.01) < 0
mask_r = 1 - mask_r
mask_g = (img[:, :, 1] - max_val + 0.01) < 0
mask_g = 1 - mask_g
mask_b = (img[:, :, 2] - max_val + 0.01) < 0
mask_b = 1 - mask_b
ratio_max= mask_r * Color_ratio[4] + mask_g * Color_ratio[0] + mask_b * Color_ratio[2]
I_out = max_val * 1.0
I_out = (max_val-mid_val)*ratio_max + (mid_val-min_val)*ratio_max_mid + min_val
plt.figure()
plt.imshow(img/255.0)
plt.axis('off')
plt.figure(2)
plt.imshow(I_out/255.0, plt.cm.gray)
plt.axis('off')
plt.show()
Python: PS 图像调整--黑白的更多相关文章
- Python: PS 图像调整--明度调整
本文用 Python 实现 PS 图像调整中的明度调整: 我们知道,一般的非线性RGB亮度调整只是在原有R.G.B值基础上增加和减少一定量来实现的,而PS的明度调整原理还得从前面那个公式上去找.我们将 ...
- Python: PS 图像调整--饱和度调整
本文用 Python 实现 PS 图像调整中的饱和度调整算法,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...
- Python: PS 图像调整--亮度调整
本文用 Python 实现 PS 图像调整中的亮度调整,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/2 ...
- Python: PS 图像调整--对比度调整
本文用 Python 实现 PS 里的图像调整–对比度调整.具体的算法原理如下: (1).nRGB = RGB + (RGB - Threshold) * Contrast / 255 公式中,nRG ...
- Python: PS 图像调整--颜色梯度
本文用 Python 实现 PS 中的色彩图,可以看到颜色的各种渐变,具体的效果可以参考以前的博客: http://blog.csdn.net/matrix_space/article/details ...
- PS 图像调整算法——黑白
这个算法是参考自 阿发伯 的博客: http://blog.csdn.net/maozefa 黑白调整 Photoshop CS的图像黑白调整功能,是通过对红.黄.绿.青.蓝和洋红等6种颜色的比例调节 ...
- PS 图像调整算法——自动对比度 (Auto Contrast)
PS 给出的定义: Enhance Monochromatic Contrast: Clips all channels identically. This preserves the overall ...
- PS 图像调整算法——自动色阶 (Auto Levels)
PS 给出的定义: Enhance Per Channel Contrast:Maximizes the tonal range in each channel to produce a more d ...
- PS 图像调整算法— —渐变映射
这个调整简单来说就是先建立一张lookup table, 然后以图像的灰度值作为索引,映射得到相应的颜色值.图像的灰度值是由图像本身决定的,但是lookup table 却可以各种各样,所以不同的lo ...
随机推荐
- POJ 2154
这题的时间卡的.... 必须用欧拉来优化,而且要加素数表.最重要是,因为最后结果要/n,而数据很大,所以,必须在之前就先/n了,否则会爆数据. #include <iostream> #i ...
- 零基础学HTML 5实战开发(第一季)
開始学习html5了.趋势不得不学习啊,之前老毛说过落后就要挨打,如今是不学习就要被市场淘汰,被社会淘汰.喜欢挑战,喜欢冒险.来吧.csdn给我们提供了那么好的平台.用起来..零基础学HTML 5的实 ...
- swoole-tcp-server
swoole-tcp-server 标签(空格分隔): php,linux 执行程序 php swoole_server.php 查看端口:netstat -antpl 连接服务器:telnet ip ...
- POJ 3188暴搜
题意: 思路: 裸的暴搜 --. 但是要注意如果你不用所有的按键就能输出最优解的话一定要把所有的字母都安排到一个位置-. 我的一群PE就是这么来的-- 为什么写的人这么少-- // by Sirius ...
- spark thrift server configuration
# MainApplicationProperties # --master yarn --deploy-mode client 下的配置, client 模式表示,driver 是在本地机器上跑的, ...
- jqGrid收藏的链接
http://zld406504302.iteye.com/blog/1694017 http://blog.csdn.net/jiudihanbing/article/details/2455902 ...
- Android TextView加上阴影效果
<TextView android:id="@+id/test_shadow" android:layout_width="wrap_content" a ...
- ActiveMQ学习笔记(17)----Message高级特性(一)
1. Messaage Properties ActiveMQ支持很多消息属性,具体可以参考 http://activemq.apache.org/activemq-message-propertie ...
- schema文件及XML文件的DOM和Sax解析
schema文件 <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="htt ...
- tigergao
互联网从业 6 年.前码农&DBA,现运维&电商创业者,也在做自媒体.终生学习者. 运营微信公众号:高哥咋么看 感兴趣的朋友们可以订阅.