I've been reading about openCV recently and its cv::Mat
data structure. In the documentation, the author keeps mentioning about multi-channel array and multi-channel matrix. Can some one give me a definition of those two, and what is a "channel"? I tried to find on google but found nothing similar.
Multi-channel matrix/array
if you have a 2d matrix you have width*height ELEMENTS. If each element is a single value you have a single channel matrix. If each element has multiple values the matrix has multiple channels. Example for single channel matrix is a grayscale image (each pixel 1 intensity value), exanple for multi channel matrix is an RGB image (each pixel are 3 values) –
Crat
The most basic example is a standard image. It has a width (cols
), a height (rows
) and 3 color channels.
Mat myImg = imread("color_picture.jpg");
Vec3b pixel = myImg.at<Vec3b>(y, x);
In this case, myImg
will be a CV_8UC3
-- 3 channels of 8 bit, unsigned integers.
I prefer to use the templated class, because I feel it's more clear:
Mat_<Vec3b> myImg = imread("color_picture.jpg");
// Or, Mat3b myImg = ...
Vec3b pixel = myImg(y, x);
Then, pixel is Blue, Green, Red:
uchar blue = pixel[0];
© 2022 - 2024 — McMap. All rights reserved.