// 图像通道分离与合并
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    string image_path = "../img/1.png";
    Mat image = imread(image_path);
    Mat result = image.clone();
    // 定义向量数组接收通道
    vector<Mat> channels;
    // 拆分
    split(result, channels);

    Mat b = channels[0];
    Mat g = channels[1];
    Mat r = channels[2];

    imshow("Blue Channel (Grayscale)", channels[0]);
    imshow("Green Channel (Grayscale)", channels[1]);
    imshow("Red Channel (Grayscale)", channels[2]);

    // merge
    Mat merged_img;
    vector<cv::Mat> channels_to_merge;
    channels_to_merge.push_back(b);
    channels_to_merge.push_back(g);
    channels_to_merge.push_back(r);

    merge(channels_to_merge, merged_img);
    imshow("merged", merged_img);

    waitKey(0);

    return (0);
}