参考:

闲人阿发伯的博客

// 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. 【cocos2dx 3.3】口袋空战5 总结与公布

    打包好的APK:点击下载

  2. github-readme.md-格式

    大标题 大标题一般显示project名,类似html的<h1> 你仅仅要在标题以下跟上=====就可以 中标题 中标题一般显示重点项,类似html的<h2> 你仅仅要在标题以下 ...

  3. sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

  4. vue v-on命令

    <!-- 阻止单击事件冒泡 --> <a v-on:click.stop="doThis"></a>   <!-- 提交事件不再重载页面 ...

  5. 【python】-- web开发之jQuery

    jQuery jQuery 是一个 JavaScript 函数库,jQuery库包含以下特性(HTML 元素选取.HTML 元素操作.CSS 操作.HTML 事件函数.JavaScript 特效和动画 ...

  6. 内存使用分析工具Valgrind简单用法

    转载自 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html 暂时还未使用过,记录下,记录下,记录下 Valgrind的主要作者 ...

  7. Android系统移植与调试之------->如何修改Android默认字体大小和设置里面字体大小比例

    因为我修改 ro.sf.lcd_density的值,将它从160修改 为120,所以导致整个系统的字体都变得很小.因此需要将整个字体变大,并且在设置-->显示-->字体大小的4个选项的值都 ...

  8. python网络爬虫之scrapy 调试以及爬取网页

    Shell调试: 进入项目所在目录,scrapy shell “网址” 如下例中的: scrapy shell http://www.w3school.com.cn/xml/xml_syntax.as ...

  9. Android 常用的权限

    添加WiFi以及访问网络的权限:    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE&q ...

  10. 【Prometheus】第三篇:配置alertmamager

    监控系统中非常重要的一环,就是告警,系统得在故障发生的第一时间将事件发送出来,通知干系人,prometheus提供了alertmanager来实现这个功能. 第一步:prometheus.yml配置文 ...