OpenCV——饱和度调整
参考:
// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
using namespace std;
using namespace cv;
void Show_Image(Mat&, const string &);
#endif // PS_ALGORITHM_H_INCLUDED
/*
This program adjust
the saturation.
*/
#include "PS_Algorithm.h"
#include <time.h>
using namespace std;
using namespace cv;
int main(void)
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name);
Show_Image(Img, Img_name);
Mat Img_out(Img.size(), CV_32FC3);
Img.convertTo(Img_out, CV_32FC3);
Mat Img_in(Img.size(), CV_32FC3);
Img.convertTo(Img_in, CV_32FC3);
// define the iterator of the input image
MatIterator_<Vec3f> inp_begin, inp_end;
inp_begin=Img_in.begin<Vec3f>();
inp_end =Img_in.end<Vec3f>();
// define the iterator of the output image
MatIterator_<Vec3f> out_begin, out_end;
out_begin=Img_out.begin<Vec3f>();
out_end =Img_out.end<Vec3f>();
// increment (-100.0, 100.0)
float Increment=-50.0/100.0;
float delta=0;
float minVal, maxVal;
float t1, t2, t3;
float L,S;
float alpha;
for(; inp_begin!=inp_end; inp_begin++, out_begin++)
{
t1=(*inp_begin)[0];
t2=(*inp_begin)[1];
t3=(*inp_begin)[2];
minVal=std::min(std::min(t1,t2),t3);
maxVal=std::max(std::max(t1,t2),t3);
delta=(maxVal-minVal)/255.0;
L=0.5*(maxVal+minVal)/255.0;
S=std::max(0.5*delta/L, 0.5*delta/(1-L));
if (Increment>0)
{
alpha=max(S, 1-Increment);
alpha=1.0/alpha-1;
(*out_begin)[0]=(*inp_begin)[0]+((*inp_begin)[0]-L*255.0)*alpha;
(*out_begin)[1]=(*inp_begin)[1]+((*inp_begin)[1]-L*255.0)*alpha;
(*out_begin)[2]=(*inp_begin)[2]+((*inp_begin)[2]-L*255.0)*alpha;
}
else
{
alpha=Increment;
(*out_begin)[0]=L*255.0+((*inp_begin)[0]-L*255.0)*(1+alpha);
(*out_begin)[1]=L*255.0+((*inp_begin)[1]-L*255.0)*(1+alpha);
(*out_begin)[2]=L*255.0+((*inp_begin)[2]-L*255.0)*(1+alpha);
}
}
Img_out=Img_out/255.0;
Show_Image(Img_out, "out");
imwrite("out.jpg", Img_out*255);
waitKey();
cout<<"All is well."<<endl;
}
// define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image);
}
原图
效果图
OpenCV——饱和度调整的更多相关文章
- PS 图像调整算法——饱和度调整
算法参考自 阿发伯 的博客. http://blog.csdn.net/maozefa 饱和度调整 图像的饱和度调整有很多方法,最简单的就是判断每个象素的R.G.B值是否大于或小于128,大于加上调整 ...
- Python: PS 图像调整--饱和度调整
本文用 Python 实现 PS 图像调整中的饱和度调整算法,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...
- C# vb .net实现饱和度调整特效滤镜
在.net中,如何简单快捷地实现Photoshop滤镜组中的饱和度调整呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一 ...
- GPUImage中饱和度调整的实现——GPUImageSaturationFilter
饱和度saturation,是指色彩的鲜艳程度,也称色彩的纯度.饱和度取决于该色中含色成分和消色成分(灰色)的比例.含色成分越大,饱和度越大:消色成分越大,饱和度越小.纯的颜色都是高度饱和的,如鲜红, ...
- Opencv学习笔记4:Opencv处理调整图片亮度和对比度
一.理论基础 在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式: 在图像像素中其中: 参数f(x)表示源图像像素. 参数g(x) 表示输出图像像素. 参数a(需要满足a> ...
- OpenCV尺寸调整
#include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...
- OpenCV——黑白调整
参考算法: 闲人阿发伯的博客 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUD ...
- Unity Shader-后处理:简单的颜色调整(亮度,饱和度,对比度)
好久没坚持写blog了,是时候开始撸一波新博文了!学习Unity有一段时间了,关于Shader的书也看了几本<Unity Shader入门精要>,<Unity 3D ShaderLa ...
- ISP模块之色彩增强算法--HSV空间Saturation通道调整 .
色彩增强不同于彩色图像增强,图像增强的一般处理方式为直方图均衡化等,目的是为了增强图像局部以及整体对比度.而色彩增强的目的是为了使的原有的不饱和的色彩信息变得饱和.丰富起来.对应于Photoshop里 ...
随机推荐
- 反素数ant(数学题)
1053: [HAOI2007]反素数ant Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2872 Solved: 1639[Submit][St ...
- Java中List.remove报UnsupportedOperationException异常
今天项目中有个需求场景: A和B都是List,而B是A的子集,现在想求A和B的差集. 想到了List中提供的removeAll()方法可以求得差集,但是结果确报了UnsupportedOperatio ...
- 九度OJ 1002:Grading
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18410 解决:4753 题目描述: Grading hundreds of thousands of Graduate Entrance ...
- linux下查找指定时间内修改过的或新建的文件
1.简单命令 # find -type f \( -newermt '2017-04-19 00:00' -a -not -newermt '2017-04-27 23:59' \) 2.简单实现(参 ...
- java.time.format.DateTimeFormatter
Java的日期与时间 DateTimeFormatter类是Java 8中日期时间功能里,用于解析和格式化日期时间的类,位于java.time.format包下. 1.预定义的DateTimeFo ...
- 打开或者 关闭 php 的错误报告
一般线上的环境,我会 php的报错信息屏蔽掉,php.ini 设置的办法 如下: display_errors = Off error_reporting = E_ALL 在代码中,可以这样~~: e ...
- QT发布的EXE打包压缩成单文件
Enigma virtual box 是免费的软件虚拟化工具,它可以将多个文件封装到您的应用程序主文件,这样您的软件就可以制作成为单文件的绿色软件. enigma virtual box 支持所有类型 ...
- Git——基本思想和工作原理(二)
核心知识点: 1.Git关注文件数据的整体是否发生变化,对更新的文件做一个快照,然后保存一个指向快照的索引,而不会关注文件数据的具体变化. 2.Git版本的更新几乎都发生在本地,不会因为没有网络而不能 ...
- LeetCode:移动零【283】
LeetCode:移动零[283] 题目描述 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序. 示例: 输入: [0,1,0,3,12] 输出: [1,3 ...
- Swift URL encode
前言 在WEB前端开发,服务器后台开发,或者是客户端开发中,对URL进行编码是一件很常见的事情,但是由于各个年代的RFC文档中的内容一直在变化,一些年代久远的代码就对URL编码和解码的规则和现在的有一 ...