Struggling with this topic for days as I wanted to associate the digital pixels to points in PCD.
I messed around with the basic concepts of pixel intensity, gray scale images, channels in image matrix in OpenCV.
This helped a lot.
an example for a single channel grey scale image (type 8UC1) and pixel coordinates x and y:
intensity.val[0] contains a value from 0 to 255.Scalar intensity = img.at<uchar>(y, x);
Note the ordering of x and y. Since in OpenCV images are represented by the same structure as matrices, we use the same convention for both cases - the 0-based row index (or y-coordinate) goes first and the 0-based column index (or x-coordinate) follows it.
a 3 channel image with BGR color ordering (the default format returned by imread):
Vec3f intensity = img.at<Vec3f>(y, x); float blue = intensity.val[0]; float green = intensity.val[1]; float red = intensity.val[2];