在opencv中访问多通道阵列中的整个通道

时间:2014-04-02 11:31:05

标签: c++ opencv image-processing mat

我正在尝试在opencv中访问3通道图像中的整个通道(用整个矩阵替换通道,见下文)。是否可以在不循环单个像素值的情况下这样做?

Mat RGB(320, 480, CV_8UC3)
Mat R(320, 480, CV_8UC1)
Mat G(320, 480, CV_8UC1)
Mat B(320, 480, CV_8UC1)

// First channel of RGB = R
// second channel of RGB = G
// third channel fo RGB = B

1 个答案:

答案 0 :(得分:4)

只需使用splitmerge

即可
Mat RGB // source mat
Mat BGR_3[3]; 
split(RGB,RGB_3);  
BGR_3[0]//do some operation Blue channel
BGR_3[1]//do some operation Green Channel
BGR_3[2]//do some operation Red channel

//later merge
Mat dst
merge(BGR_3,3,dst);