用OpenCV实现Photoshop算法(七): 调整色相饱和度
来源:互联网 发布:如何还原手机网络设置 编辑:程序博客网 时间:2024/05/16 08:36
系列文章:
用OpenCV实现Photoshop算法(一): 图像旋转
用OpenCV实现Photoshop算法(二): 图像剪切
用OpenCV实现Photoshop算法(三): 曲线调整
用OpenCV实现Photoshop算法(四): 色阶调整用OpenCV实现Photoshop算法(五): 亮度对比度调整
用OpenCV实现Photoshop算法(六): 变为黑白图像
用OpenCV实现Photoshop算法(七): 调整色相饱和度
用OpenCV实现Photoshop算法(八): 可选颜色
用OpenCV实现Photoshop算法(九): 高反差保留
七、调整色相饱和度
Photoshop 的色相/饱和度调整,可以对全图、红、黄、绿、青、蓝、洋红六个通道进行设置。
每个通道可设置: 色相(hue), 饱和度(satuation), 明度(Lightness)三个调整值。
(一)颜色空间 (Color Space)
颜色空间也称彩色模型(又称彩色空间). 常用颜色空间有:RGB, HSL, CYMK, Lab等。
对于RGB图像,所谓色相/饱和度调整,就是把 RGB 转为 HSL, 再对色相(H), 饱和度(S), 明度(L)进行调整,然后再转回RGB.
(二)OpenCV代码实现
1,我用OpenCV 编写了多个 颜色空间转换函数, 在源文件 ColorSpace.hpp, ColorSpace.cpp中
2,我用OpenCV 编写了一个 HSL类,实现色相/饱和度调整。在源文件 ColorSpace.hpp, ColorSpace.cpp中
3, 使用方法: HSL类有一个属性channels[7], 定义了7个颜色通道。每个通道有hue, saturation, brightness三个值。设置好所需通道和值,再调用HSL类的adjust()方法即可对图像进行 色相/饱和度调整。
4, 源文件及例程源码下载在这里: 调整色相饱和度源码
(三)例程
使用HSL类,进行色相/饱和度调整。
#include <iostream>#include "opencv2/core.hpp"#include "opencv2/imgproc.hpp"#include "opencv2/highgui.hpp"#include "HSL.hpp"using namespace std;using namespace cv;static string window_name = "photo";static Mat src;static HSL hsl;static int color = 0;static int hue = 180;static int saturation = 100;static int brightness = 100;static void callbackAdjust(int , void *){Mat dst;hsl.channels[color].hue = hue - 180;hsl.channels[color].saturation = saturation - 100;hsl.channels[color].brightness = brightness - 100;hsl.adjust(src, dst);imshow(window_name, dst);}static void callbackAdjustColor(int , void * ){hue = hsl.channels[color].hue + 180;saturation = hsl.channels[color].saturation + 100;brightness = hsl.channels[color].brightness + 100;setTrackbarPos("hue", window_name, hue);setTrackbarPos("saturation", window_name, saturation);setTrackbarPos("brightness", window_name, brightness);callbackAdjust(0, 0);}int main(){src = imread("building.jpg");if ( !src.data ) {cout << "error read image" << endl;return -1;}namedWindow(window_name);createTrackbar("color", window_name, &color, 6, callbackAdjustColor);createTrackbar("hue", window_name, &hue, 2*hue, callbackAdjust);createTrackbar("saturation", window_name, &saturation, 2*saturation, callbackAdjust);createTrackbar("brightness", window_name, &brightness, 2*brightness, callbackAdjust);callbackAdjust(0, 0);waitKey();return 0;}
运行效果:
原图:
对蓝色通道(color = 5)调整hue, brightness后
再对全图(color = 0)调整saturation, brightness后
- 用OpenCV实现Photoshop算法(七): 调整色相饱和度
- C++实现Photoshop色相/饱和度/明度功能
- PhotoShop算法实现--色调/饱和度调整(四)
- 图片饱和度,色相,亮度调整
- Photoshop图像处理算法—饱和度调整
- 用OpenCV实现Photoshop算法(三): 曲线调整
- 用OpenCV实现Photoshop算法(四): 色阶调整
- 用OpenCV实现Photoshop算法(五): 亮度对比度调整
- Photoshop 系列:色阶-曲线-色相和饱和度
- Delphi图像处理 -- 色相/饱和度调整
- as3.0 用代码设置“调整颜色”滤镜--------即:亮度、对比度、饱和度、色相的调整
- as3.0 用代码设置“调整颜色”滤镜--------即:亮度、对比度、饱和度、色相的调整
- 色相&饱和度
- Delphi图像处理 -- 色相/饱和度调整(续)
- OpenCV——饱和度调整
- opencv调节图像色相、饱和度、明度(H\S\V)
- ps 色相/饱和度,描边,外发光算法(opengl)
- 色相、明度及饱和度
- 重载赋值函数与复制构造函数
- 13. Roman to Integer
- 技术博客地址
- 原生表单提交的方式
- HDU3339-In Action(最短路+01背包)
- 用OpenCV实现Photoshop算法(七): 调整色相饱和度
- 不同等级raid的读写性能,优缺点,所需最小硬盘数以及结构
- 80x86机器指令
- Intel汇编程序设计-整数算术指令(下)
- Hibernate--什么是持久化?
- 用NodeJS实现一个简单的聊天室
- 设计模式——简单工厂模式(C++)
- 【项目技术点】浏阳市国土资源交易系统-WCF项目设计技术点总结
- Smack如何获取房间表单参数