PS 图像调整算法——自动对比度 (Auto Contrast)
PS 给出的定义:
Enhance Monochromatic Contrast: Clips all channels identically. This preserves the overall color relationship while making highlights
appear lighter and shadows appear darker. The Auto Contrast command uses this algorithm.
和自动色阶不一样的地方在于,自动对比度不是三个通道分别调整,而是三个通道同时调整,可以先获取图像的亮度信息,然后根据 clipping percentage 对亮度进行动态范围的拉伸,根据拉伸前后亮度的比率,可以同比例调整R,G,B 三个通道,这样调整的图像不会出现色偏的问题。
先拉伸亮度的动态范围,可以借用自动色阶里的函数。
function I_out=F_color(I, percent)
%%% the tonal range of the input image is 0-1.
[row, col]=size(I);
I_sort=sort(I(:));
I_out=I;
%%% based on the clipping percentage,
%%% compute the upper and lower boundaries
if (percent==0)
I_min=min(I_sort)
I_max=max(I_sort)
else
I_min=I_sort(floor(row*col*percent))
I_max=I_sort(floor(row*col*(1-percent)))
end
for i=1:row
for j=1:col
if(I(i,j)<I_min)
I_out(i,j)=I_min;
elseif(I(i,j)>I_max)
I_out(i,j)=1;
else
I_out(i,j)=(I(i,j)-I_min)*(1-I_min)/(I_max-I_min)+I_min;
end
end
end
利用拉伸前后亮度的比率,同比例调整R,G,B三个通道。
clc;
clear all;
Image=imread('8.jpg');
Image=double(Image)/255;
imshow(Image);
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
I=R*0.2989+G*0.5871+0.1140*B;
I=I/(max(I(:)));
percent=0.001;
I_out=F_color(I, percent);
delta=0.0001;
K=(I_out+delta)./(I+delta);
Image_out(:,:,1)=R.*K;
Image_out(:,:,2)=G.*K;
Image_out(:,:,3)=B.*K;
figure, imshow(Image_out);
原图:
调整后的图:
最新文章
- SCons - 简单而强大的项目编译脚本
- python 中偏函数 partial 的使用
- bzoj 1877: [SDOI2009]晨跑
- SqlServer 事务和异常处理示例
- 题解西电OJ (Problem 1003 -最喜欢的数字)--动态规划
- Web前端性能优化的14条规则
- Redis intset
- Git双机同步
- Webpack多入口文件、热更新等体验
- ROS多机通信计算机网络配置
- JavaScript中Object的总结
- Struts2上传文件出错
- BZOJ 1500/Luogu 2042 - 维修数列 - [NOI2005][Splay]
- 常量,变量,a++,++a,+=等
- selenium 模拟手机
- 20155306 白皎 0day漏洞——漏洞利用原理之DEP
- javascript 浮点数加减乘除计算会有问题, 整理了以下代码来规避这个问题
- ZOJ 2969 Easy Task
- Python 装饰器Decorator(二)
- idea中tomcat乱码问题解决
热门文章
- 1CCTableView的使用,TableView响应和小格子tableView实现
- EJB开发第一个无状态会话bean、开发EJB客户端
- Android必知必会-使用okhttp的PUT方式上传文件
- EBS系统克隆
- 【java线程系列】java线程系列之线程间的交互wait()/notify()/notifyAll()及生产者与消费者模型
- JPA(三)之实体关系一对多(多对一)
- Java-IO之BufferedInputStream(缓冲输入流)
- eclipse代码恢复(开发程序代码恢复)
- [Redmine] Centos5上安装Redmine3.0+nginx+thin部署
- Linux IPC实践(7) --Posix消息队列