如何处理多通道矩阵

时间:2013-02-08 15:25:30

标签: opencv

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

谢谢

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

流程1:

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

Explanation of the above

过程2(lil冗长..)

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

编辑... for 4 CHANNEL ..

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