c++ code

--------

#include <vector>

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

int main()

{

        cv::Mat image1;

        cv::Mat image2;

        cv::Mat result;

        image1= cv::imread("greek_sunset.jpg");

        image2= cv::imread("halleys_comet.jpg");

        if (!image1.data)

                return 0;

        if (!image2.data)

                return 0;

        // using overloaded operator

        result= 0.7*image1+0.9*image2;

        cv::namedWindow("result with operators");

        cv::imshow("result with operators",result);

        image2= cv::imread("halleys_comet.jpg",0);

        cv::namedWindow("Image 1");

        cv::imshow("Image 1",image1);

        cv::namedWindow("Image 2");

        cv::imshow("Image 2",image2);

        // create vector of 3 images

        std::vector<cv::Mat> planes;

        // split 1 3-channel image into 3 1-channel images

        cv::split(image1,planes);

        // add to blue channel

        planes[0]+= image2;

        // merge the 3 1-channel images into 1 3-channel image

        cv::merge(planes,result);

        cv::namedWindow("Result on blue channel");

        cv::imshow("Result on blue channel",result);

        cv::waitKey(0);

        return 0;

}

python code

------------------

import cv2

img = cv2.imread("opencv_logo.png")

(b, g, r) = cv2.split(img)

#(channel_b, channel_g, channel_r) = (img[:,:,0], img[:,:,1], img[:,:,2])

cv2.namedWindow('blue logo')

cv2.namedWindow('green logo')

cv2.namedWindow('red logo')

cv2.namedWindow('merged')

cv2.imshow('blue logo', b)

cv2.imshow('green logo', g)

cv2.imshow('red logo', r)

img = cv2.merge((b,g,r))

cv2.imshow('merged', img)

cv2.waitKey(0)

cv2.destroyAllWindows()