参考:

闲人阿发伯的博客

// 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——饱和度调整的更多相关文章

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

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

  2. Python: PS 图像调整--饱和度调整

    本文用 Python 实现 PS 图像调整中的饱和度调整算法,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...

  3. C# vb .net实现饱和度调整特效滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的饱和度调整呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一 ...

  4. GPUImage中饱和度调整的实现——GPUImageSaturationFilter

    饱和度saturation,是指色彩的鲜艳程度,也称色彩的纯度.饱和度取决于该色中含色成分和消色成分(灰色)的比例.含色成分越大,饱和度越大:消色成分越大,饱和度越小.纯的颜色都是高度饱和的,如鲜红, ...

  5. Opencv学习笔记4:Opencv处理调整图片亮度和对比度

    一.理论基础 在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式: 在图像像素中其中: 参数f(x)表示源图像像素. 参数g(x) 表示输出图像像素. 参数a(需要满足a> ...

  6. OpenCV尺寸调整

    #include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...

  7. OpenCV——黑白调整

    参考算法: 闲人阿发伯的博客 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUD ...

  8. Unity Shader-后处理:简单的颜色调整(亮度,饱和度,对比度)

    好久没坚持写blog了,是时候开始撸一波新博文了!学习Unity有一段时间了,关于Shader的书也看了几本<Unity Shader入门精要>,<Unity 3D ShaderLa ...

  9. ISP模块之色彩增强算法--HSV空间Saturation通道调整 .

    色彩增强不同于彩色图像增强,图像增强的一般处理方式为直方图均衡化等,目的是为了增强图像局部以及整体对比度.而色彩增强的目的是为了使的原有的不饱和的色彩信息变得饱和.丰富起来.对应于Photoshop里 ...

随机推荐

  1. 验证-- email类型输入框(电子邮件地址)--multiple

    如果需要一个用来填写电子邮件地址的输入框,可以使用email类型.这样浏览器可以帮我们验证格式是否正确,而不需要自己写验证规则.原文:HTML5新控件 - email类型输入框(电子邮件地址) 1,只 ...

  2. 【v2.x OGE教程 11】 动画编辑器帮助文档

    ] 动画编辑器帮助文档 版本号 日期 作者 说明 1.0 2014-9-3 橙子游戏 文档创建       一.简单介绍 动画编辑器用于游戏动画的可视化编辑,支持序列帧动画和关键帧动画.通过解析生成的 ...

  3. jquery获取页面iframe内容

    //取得整个HTML格式 var f = $(window.frames["ReportIFrame"].document).contents().html(); 或者 $(&qu ...

  4. Idea 使用的技巧和设置

    1.自动提示时候,忽绿大小写, setting---->sensitive 2:IntelliJ IDEA报错class is never used 图中的unused declaration选 ...

  5. JavaScript点击事件-一个按钮触发另一个按钮

    <input type="button" value="Click" id="C" onclick="Go();" ...

  6. linux c编程:进程控制(二)_竞争条件

    前面介绍了父子进程,如果当多个进程企图对共享数据进行处理.而最后的结果又取决于进程运行的顺序时,就认为发生了竞争关系.通过下面的例子来看下 在这里标准输出被设置为不带缓冲的,于是父子进程每输出一个字符 ...

  7. ubuntu 安装vagrant过程

    Ubuntu安装vagrant时需要首先安装virtualBox. Step1: 在https://www.virtualbox.org/wiki/Linux_Downloads 下载ubuntu对应 ...

  8. tool class

    在Java中,工具类定义了一组公共方法,这篇文章将介绍Java中使用最频繁及最通用的Java工具类.以下工具类.方法按使用流行度排名,参考数据来源于Github上随机选取的5万个开源项目源码. 一. ...

  9. Javaweb基础--->监听器listener(转发)

    JavaWeb中的监听器 1.基本概念 JavaWeb中的监听器是Servlet规范中定义的一种特殊类,它用于监听web应用程序中的ServletContext, HttpSession和 Servl ...

  10. python3 str和bytes转换

    bytes object b = b"example" str object s = "example" #str to bytes bytes(s, enco ...