<Vec3b> giving 3 values for grayscale image

When I’m reading image as COLOR image, I’m getting appropriate intensity (3 values) at each at pixel (y,x).

 Vec3b intensity =<Vec3b>(y, x);
 unsigned int blue = intensity.val[0];
 unsigned int green = intensity.val[1];
 unsigned int red = intensity.val[2];

However, when I’m reading same image as GRAYSCALE, and trying to applying same code as above, I’m still getting 3 intensity values. & all the 3 values are different compared to if I read intensity for single channel using below code:

 uchar intensity =<uchar>(y, x);

Not understanding why I’m getting 3 values for grayscale image and that to something different from actual gray pixel intensities.
Thanks in advance.

if it’s grayscale, then accessing with Vec3b is an error

indeed, those are the next 2 grayscale pixels.

if you run a debug build, you should get a proper exception