【问题标题】:How to handle multi-channel matrix如何处理多通道矩阵
【发布时间】:2013-02-09 02:56:16
【问题描述】:

我有一个 500x500 Mat 对象(图像的绿色平面)。 我创建了一个 500x500x3(其中 3 是通道数)零 Mat 对象。 是否有一个 openCV 2.4.3 函数可以在新的“零”Mat 对象的第二个通道中复制绿色平面?

谢谢

【问题讨论】:

    标签: opencv


    【解决方案1】:

    流程一:

    int from_to[] = {0,1}
    mixChannels(Green_plane,1,Created_mat,3,from_to,1);
    

    Explanation of the above

    过程 2(略长..)

    Mat Green_plane;//you already have this matrix as the green plane of an image
    
    //create a 3 channeled matrix with all entries set to zero
    Mat Created_mat = Mat::zeros(rows,cols,CV_8UC3);
    
    //its a vector array of images that will contain the 3 planes of the above 3 channeled   matrix
    vector<Mat> bgr_plane;
    
    // divide the 3 channeled matrix into 3 one channeled matrix
    split(Created_mat,bgr_plane);
    
    // take the green plane, which is the middle matrix out of the 3 matrices contained in the vector array bgr_planes, and copy your already given green matrix to it
    bgr_plane[1] = Green_plane.clone();
    
    //merge the vector of one channeled matrices into a 3 channeled matrix
    merge(bgr_plane,Created_mat);//EDITED
    
    // now Created_mat has the green channel same as given green matrix you already have (Green_plane) and the rest 2 planes are still set to zero
    

    编辑...为 4 通道..

    vector<Mat> each_channel;
    split(Mat_4_channel,each_channel);
    
    //accessing each pixel of each channel
    each_channel[0].at<uchar>(row,col);//1st channel
    each_channel[1].at<uchar>(row,col);//2nd channel
    each_channel[2].at<uchar>(row,col);//3rd channel
    each_channel[3].at<uchar>(row,col);//4th channel
    

    【讨论】:

    • 您能逐个解释您的代码实际执行的功能吗?非常感谢
    • 太棒了!我唯一的问题是“合并”被强调为错误(重载)。你怎么看?
    • ok...第一个代码有错误,你必须换成合并合并。现在好了,非常感谢
    • 现在我有另一个问题:如何在 Created_mat 的像素级别访问它???像这样:ACreated_mat.at(ii,jj)[k];
    【解决方案2】:
    void mixChannels(const vector<Mat>& srcv, vector<Mat>& dstv, const int* fromTo, int npairs)
    

    有关此功能的更多信息,请访问:http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#mixChannels

    【讨论】:

      猜你喜欢
      • 2016-05-24
      • 1970-01-01
      • 2016-04-23
      • 2014-04-03
      • 2017-06-02
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多