简体   繁体   中英

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?

在这里参考文档

Mat src1 = imread(inputImageFilename1.c_str(), 1); # make sure flag > 0

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

For someone, still confused, here you go. I assume the OP is referring to a coloured image. OpenCV represents the image as [Blue, Green, Red] (because BGR was more popular in the 90's compared to RGB). Let's take an example of a 3 x 3 image. It would be represented as follows: Image showing a 3D matrix

I hope it solves the query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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