opencv3.2.0 分离颜色通道&多通道图像混合

##名称:分离颜色通道&多通道图像混合
##平台:QT5.7.1+OpenCV3.2.0
##时间:2017年12月11日
/***************创建QT控制台程序*******************/
#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main()
{
    //定义相关变量
    Mat image;
    Mat imageGray;
    Mat imageGreenChannel,imageBlueChannel,imageRedChannel;
    Mat imageBlue,imagePurple,imageGreen,imageYellow,imageRed;
    vector<Mat> channels;

    image = imread("/home/ttwang/Valley_logo.jpg");       //读入原图
    imageGray = imread("/home/ttwang/Valley_logo.jpg",0); //读入灰度图

    /***************得到蓝色通道图和紫色通道图*****************/
    split(image,channels);//分离彩色通道

    imageBlueChannel = channels.at(0); //蓝色通道的引用返回给imagBlueChannel
    addWeighted(imageBlueChannel,1.0,imageGray,0.5,0,imageBlueChannel);//混合后的蓝色通道

    merge(channels,imageBlue);//此时蓝色通道已经变味了,
                         //再通过merge将三个通道重新合并成一个三通道,便得到蓝色通道图

    imageRedChannel = channels.at(2);  //在上面处理后的基础上,分离红色通道,可得到紫色通道图
    addWeighted(imageRedChannel,1.0,imageGray,0.5,0,imageRedChannel);
    merge(channels,imagePurple);

    imshow("blue",imageBlue);
    imshow("purple",imagePurple);

    /***************得到绿色通道图和黄色通道图*****************/
    split(image,channels);//要想出现绿色的图像,需要对原图进行重新分离
    imageGreenChannel = channels.at(1);
    addWeighted(imageGreenChannel,1.0,imageGray,0.5,0,imageGreenChannel);
    merge(channels,imageGreen);

    imageGreenChannel = channels.at(2);
    addWeighted(imageRedChannel,1.0,imageGray,0.5,0,imageRedChannel);
    merge(channels,imageYellow);

    imshow("green",imageGreen);
    imshow("yellow",imageYellow);

    /***************得到红色通道图*****************/
    split(image,channels);
    imageRedChannel = channels.at(2);
    addWeighted(imageRedChannel,1.0,imageGray,0.5,0,imageRedChannel);
    merge(channels,imageRed);

    imshow("red",imageRed);
    waitKey(0);
    return 0;
}

运行结果:

转载于:https://www.cnblogs.com/ilym/p/8023355.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值