Core_划分YUV颜色平面,并打乱亮度通道,合并输出
2014-03-29 20:57
381 查看
Core_划分YUV颜色平面,并打乱亮度通道,合并输出-----------
#include <Windows.h>
#include <iostream>
#include "opencv.hpp"
using namespace cv;
using namespace std;
#define DEMO_MIXED_API_USE
int main()
{
char* filename="..//images//chicky_512.png";
#ifdef DEMO_MIXED_API_USE
Ptr<IplImage> IplI=cvLoadImage(filename);
if(IplI.empty())
{
cerr<<"cant not load image"<<filename<<endl;
return -1;
}
Mat I(IplI);
#else
Mat I=imread(filename);
if(I.empty())
{
cerr<<"can not load image "<<filename<<endl;
return -1;
#endif
Mat I_YUV;
cvtColor(I,I_YUV,CV_BGR2YCrCb);
vector<Mat> planes;
split(I_YUV,planes);
MatIterator_<uchar> it=planes[0].begin<uchar>(),it_end=planes[0].end<uchar>();
for (;it!=it_end;++it)
{
double v=*it*1.7 + rand()%21 -10;
*it=saturate_cast<uchar>(v*v/255);
}
Mat noisyI(I.size(),CV_8U);
randn(noisyI,Scalar::all(128),Scalar::all(20));
GaussianBlur(noisyI,noisyI,Size(3,3),0.5,0.5);
const double brightness_gain=0;
const double contrast_gain=1.7;
#ifdef DEMO_MIXED_API_USE
IplImage cv_planes_0=planes[0],cv_noisy=noisyI;
cvAddWeighted(&cv_planes_0,contrast_gain,&cv_noisy,1,-128+brightness_gain,&cv_planes_0);
#else
addWeighted(planes[0],contrast_gain,noisyI,1,-128+brightness_gain,planes[0]);
#endif
const double color_scale=0.5;
planes[1].convertTo(planes[1],planes[1].type(),color_scale,128*(1-color_scale));
planes[2]=Mat_<uchar>(planes[2]*color_scale + 128*(1-color_scale));
planes[0]=planes[0].mul(planes[0],1.0/255);
merge(planes,I_YUV);
cvtColor(I_YUV,I,CV_YCrCb2BGR);
namedWindow("image with grain",CV_WINDOW_AUTOSIZE);
#ifdef DEMO_MIXED_API_USE
// this is to demonstrate that I and IplI really share the data - the result of the above
// processing is stored in I and thus in IplI too.
cvShowImage("image with grain", IplI);
#else
imshow("image with grain", I); // the new MATLAB style function show
#endif
waitKey(0);
return 0;
}
#include <Windows.h>
#include <iostream>
#include "opencv.hpp"
using namespace cv;
using namespace std;
#define DEMO_MIXED_API_USE
int main()
{
char* filename="..//images//chicky_512.png";
#ifdef DEMO_MIXED_API_USE
Ptr<IplImage> IplI=cvLoadImage(filename);
if(IplI.empty())
{
cerr<<"cant not load image"<<filename<<endl;
return -1;
}
Mat I(IplI);
#else
Mat I=imread(filename);
if(I.empty())
{
cerr<<"can not load image "<<filename<<endl;
return -1;
#endif
Mat I_YUV;
cvtColor(I,I_YUV,CV_BGR2YCrCb);
vector<Mat> planes;
split(I_YUV,planes);
MatIterator_<uchar> it=planes[0].begin<uchar>(),it_end=planes[0].end<uchar>();
for (;it!=it_end;++it)
{
double v=*it*1.7 + rand()%21 -10;
*it=saturate_cast<uchar>(v*v/255);
}
Mat noisyI(I.size(),CV_8U);
randn(noisyI,Scalar::all(128),Scalar::all(20));
GaussianBlur(noisyI,noisyI,Size(3,3),0.5,0.5);
const double brightness_gain=0;
const double contrast_gain=1.7;
#ifdef DEMO_MIXED_API_USE
IplImage cv_planes_0=planes[0],cv_noisy=noisyI;
cvAddWeighted(&cv_planes_0,contrast_gain,&cv_noisy,1,-128+brightness_gain,&cv_planes_0);
#else
addWeighted(planes[0],contrast_gain,noisyI,1,-128+brightness_gain,planes[0]);
#endif
const double color_scale=0.5;
planes[1].convertTo(planes[1],planes[1].type(),color_scale,128*(1-color_scale));
planes[2]=Mat_<uchar>(planes[2]*color_scale + 128*(1-color_scale));
planes[0]=planes[0].mul(planes[0],1.0/255);
merge(planes,I_YUV);
cvtColor(I_YUV,I,CV_YCrCb2BGR);
namedWindow("image with grain",CV_WINDOW_AUTOSIZE);
#ifdef DEMO_MIXED_API_USE
// this is to demonstrate that I and IplI really share the data - the result of the above
// processing is stored in I and thus in IplI too.
cvShowImage("image with grain", IplI);
#else
imshow("image with grain", I); // the new MATLAB style function show
#endif
waitKey(0);
return 0;
}
相关文章推荐
- OpenCV-颜色通道的分离、合并
- 【基于C++和Python的Opencv3学习笔记之颜色空间缩减、ROI提取及多通道分离合并】
- opencv(10)---对比度亮度调整与通道分离与合并
- python3-opencv库(3)--图片颜色空间转换,利用HSV进行物体跟踪,图像通道分离与合并
- 【OpenCV学习笔记】十二、图像的对比度和亮度调整及图像通道的分离与合并
- YUV2----将YUV420P像素数据去掉颜色(变成灰度图)和亮度减半、四周加边框
- opencv 手动调整照片颜色小工具 对比度 亮度 BGR 各通道
- .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度
- 3、excel 导出。适合用于将界面上的内容所见及所得的输出,可以设置单元格的的合并,大小,字体,颜色等等
- 硬件开发之bt输出---BT656/BT601/BT1120协议以及DM365/DM355/DM6467上使用的YUV颜色空间说明
- 五.Core组件进阶(5.通道的合并与分离)
- 转:c#:更改控制台文字输出颜色
- 一段合并多个有序数组并且升序输出数组元素的C++代码
- 肤色检测算法 - 基于不同颜色空间简单区域划分的皮肤检测算法
- LA 6263 The Dragon and the knights 平面划分 ,欧拉定理
- 【转】YUV420P的格式以及转换为RGB565的代码(Android摄像头的输出一般为YUV420P)
- 基于CoreAudio获取声卡输出电平
- 【OpenCV入门教程之五】 分离颜色通道&多通道图像混合
- OpenCV 分离颜色通道与多通道图像混合
- 三维通道下输入和输出一个矩阵