三通道图像转化为三通道,并将多通道图像混合
2016-02-02 23:03
246 查看
#include<cv.h>
#include<highgui.h>
#include<iostream>
using namespace cv;
using namespace std;
bool duotongdao();
int main()
{
if(duotongdao())
{
cout<<endl<<"恩 得到混合值图像";
}
waitKey(0);
return 0;
}
bool duotongdao()
{
Mat srcImage;
Mat logoImage;
vector<Mat>channels;
Mat imageBlueChannel;
logoImage = imread("cloud.jpg",0);//>0 Return a 3-channel color image =0 Return a grayscale image
srcImage = imread("ali.jpg");
if(!logoImage.data){
printf("no it is wrong !");
}
if(!srcImage.data){
printf("no it is wrong !");
}
//把一个3通道图像转化为3个单通道图像
split(srcImage,channels);//分离色彩通道
//将原图的蓝色通道引用返回给imageBlueChannel,注意是引用,相当于两者等价,修改其中之一,另一个跟着改变
imageBlueChannel = channels.at(0);
//将原图的蓝色通道的(100,100)坐标处右下方的一块区域和logo图进行加权操作,将得到的混合结果存到
//imageBlueChannel中
addWeighted(imageBlueChannel(Rect(100,100,logoImage.cols,logoImage.rows)),0.8,
logoImage,0.2,0,imageBlueChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
//将三个单通道重新合成一个三通道
merge(channels,srcImage);
namedWindow("logo with Blue road",WINDOW_NORMAL);
imshow("logo with Blue road",srcImage);
Mat imageGreenChannel;
logoImage=imread("cloud.jpg",0);
srcImage=imread("ali.jpg");
if(!logoImage.data ) { printf("no it is wrong !"); return false; }
if(!srcImage.data ) { printf("no it is wrong !"); return false; }
split(srcImage,channels);
imageGreenChannel=channels.at(1);
addWeighted(imageGreenChannel(Rect(100,100,logoImage.cols,logoImage.rows)),0.5,
logoImage,0.5,0,imageGreenChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
merge(channels,srcImage);
namedWindow("Green",WINDOW_NORMAL);
imshow("Green",srcImage);
Mat imageRedChannel;
logoImage=imread("cloud.jpg",0);
srcImage=imread("ali.jpg");
if(!logoImage.data ) { printf("no it is wrong !"); return false; }
if(!srcImage.data ) { printf("no it is wrong !"); return false; }
split(srcImage,channels);
imageRedChannel=channels.at(2);
addWeighted(imageRedChannel(Rect(100,100,logoImage.cols,logoImage.rows)),1.5,
logoImage,0.5,0,imageRedChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
merge(channels,srcImage);
namedWindow("Red",WINDOW_NORMAL);
imshow("Red",srcImage);
return true;
}
#include<highgui.h>
#include<iostream>
using namespace cv;
using namespace std;
bool duotongdao();
int main()
{
if(duotongdao())
{
cout<<endl<<"恩 得到混合值图像";
}
waitKey(0);
return 0;
}
bool duotongdao()
{
Mat srcImage;
Mat logoImage;
vector<Mat>channels;
Mat imageBlueChannel;
logoImage = imread("cloud.jpg",0);//>0 Return a 3-channel color image =0 Return a grayscale image
srcImage = imread("ali.jpg");
if(!logoImage.data){
printf("no it is wrong !");
}
if(!srcImage.data){
printf("no it is wrong !");
}
//把一个3通道图像转化为3个单通道图像
split(srcImage,channels);//分离色彩通道
//将原图的蓝色通道引用返回给imageBlueChannel,注意是引用,相当于两者等价,修改其中之一,另一个跟着改变
imageBlueChannel = channels.at(0);
//将原图的蓝色通道的(100,100)坐标处右下方的一块区域和logo图进行加权操作,将得到的混合结果存到
//imageBlueChannel中
addWeighted(imageBlueChannel(Rect(100,100,logoImage.cols,logoImage.rows)),0.8,
logoImage,0.2,0,imageBlueChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
//将三个单通道重新合成一个三通道
merge(channels,srcImage);
namedWindow("logo with Blue road",WINDOW_NORMAL);
imshow("logo with Blue road",srcImage);
Mat imageGreenChannel;
logoImage=imread("cloud.jpg",0);
srcImage=imread("ali.jpg");
if(!logoImage.data ) { printf("no it is wrong !"); return false; }
if(!srcImage.data ) { printf("no it is wrong !"); return false; }
split(srcImage,channels);
imageGreenChannel=channels.at(1);
addWeighted(imageGreenChannel(Rect(100,100,logoImage.cols,logoImage.rows)),0.5,
logoImage,0.5,0,imageGreenChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
merge(channels,srcImage);
namedWindow("Green",WINDOW_NORMAL);
imshow("Green",srcImage);
Mat imageRedChannel;
logoImage=imread("cloud.jpg",0);
srcImage=imread("ali.jpg");
if(!logoImage.data ) { printf("no it is wrong !"); return false; }
if(!srcImage.data ) { printf("no it is wrong !"); return false; }
split(srcImage,channels);
imageRedChannel=channels.at(2);
addWeighted(imageRedChannel(Rect(100,100,logoImage.cols,logoImage.rows)),1.5,
logoImage,0.5,0,imageRedChannel(Rect(100,100,logoImage.cols,logoImage.rows)));
merge(channels,srcImage);
namedWindow("Red",WINDOW_NORMAL);
imshow("Red",srcImage);
return true;
}
相关文章推荐
- 【行业秘密公开】所谓的QQ刷钻业务
- redis在windows_64位环境下使用
- [BZOJ3261] 最大异或和
- poj2115
- 【很棒】Postfix使用介绍
- Day12~13(2016/2/1~2/2)
- 搭建个人页面的笔记
- vim学习笔记
- 引用的实质
- python教程2 安装使用 pycharm
- 局部光照模型及其BRDF
- 四、五版币冠字号发行量统计排行
- MongoDB_记录条数limit和跳过条数skip
- .Net and C# release history
- 推荐系统和搜索引擎的关系
- Linux管理-sed
- android程序的断点单步调试步骤
- hdu1811 Rank of Tetris(待解决 拓扑排序)
- 来年春天
- Unfinished List