zoukankan      html  css  js  c++  java
  • 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;
    }

    运行结果:

  • 相关阅读:
    INV接口管理器
    取会计科目之数字
    两个有用的oracle数据库运算:intersect和minus运算
    弹出“FRM40400:事务完成:已应用和保存X条记录
    JSP连接数据库
    javaScript JSP HTML Java CSS 注释
    Android开发环境搭建全过程
    用JAVA 实现“生产者-消费者”问题
    路由器如何当交换机使用
    validateJarFile jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet
  • 原文地址:https://www.cnblogs.com/ilym/p/8023355.html
Copyright © 2011-2022 走看看