简体   繁体   English

在opencv中的多通道数组中访问整个通道

[英]Accessing Whole Channel in a multi channel array in opencv

I'm trying to access a whole channel in a 3 channel image in opencv (to replace a channel with a whole matrix, see below). 我正在尝试在opencv的3通道图像中访问整个通道(以整个矩阵替换通道,请参见下文)。 Is it possible to do so without looping through the individual pixel values? 是否可以这样做而不循环遍历各个像素值?

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

Just use split and merge 只需使用拆分合并

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);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM