您的位置:首页 > 其它

三通道图像转化为三通道,并将多通道图像混合

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: