0

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

谢谢

4

2 回答 2

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

于 2013-02-08T15:44:24.413 回答
0

过程1:

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

以上的解释

过程 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
于 2013-02-08T16:23:33.420 回答