What's the meaning of the values in the OpenCV image representation?
I am using OpenCV with Python. When I load a JPG or PNG image by calling cv2.imread()
, I get a 2D matrix, whose size is the same as the resolution of that image. Each number in the matrix is in the range of 0 to 255.
I don't understand how this matrix can represent an image. In particular, I expect to see a 3D matrix, whose third dimension represents RGB channels. If a pixel is represented by one 8-bit integer, then the whole image can only have 256 colors, but it is clearly not true.
What am I missing here?
Solution 1:
"imread" defaults the second argument to 0, which means that your image is converted to 8-bit depth grayscale. Therefore you are getting a value from 0 to 255 as a color for each pixel of your image.
Try changing your call as follows to get a 3-channel color image:
cv2.imread("yourimage.bmp",1);
Solution 2:
refer doc here
Mat src1 = imread(inputImageFilename1.c_str(), 1); # make sure flag > 0