1. Grayscale map (single channel map, black and white map)

Single-channel map refers to the number of dimensions of 2, or the third dimension of 1 map, also known as grayscale, can be understood as black and white map.

Each of the imagespixelThere can only beA valueRepresents the color, and the pixel value range is[0 ~ 255]. The following two images are both grayscale images, but the level of grayscale is different. The value of each pixel in the first image is either 0 or 255. The value of each pixel in the second image is one[0 ~ 255]Range.

II. Color diagram (RGB diagram, three-channel diagram)

Each pixel in a color map has 3 values representing the color, so it is called 3 channels. For example, an RGB image has three channels, which is called a color image.

If the values of all three channels are the same in a given location, the image will also be black and white, which looks the same as the grayscale image, but it is essentially different from the grayscale image.

It’s usually called a regular three-channel diagram. That is, a three-channel map can be grayscale, but a single-channel map can only be grayscale.

For example, the first image below is a color image, and the second image is a normal three-channel image.

3, judge the picture isgrayscaleorThree channels in black and white

Right click on the pictureattributeTo beginThe detailed informationAnd there areA depth, as shown below:

If it’s a three-channel diagram, the bit depth is 24; If it is a single channel map (grayscale map), the bit depth is 8;

Four, single channel graph and three channel graph mutual conversion

[Single channel diagram] converted to [Common three-channel diagram]

Stack_img = np.stack((gray_img,)*3, axis=-1) img = cv2.cvtColor(img, cv2.color_gray2GB)

[Single channel diagram] converted to [RGB diagram]

OpenCV, PIL do not support, need to use the color algorithm

[color diagram, three-channel diagram] into [single channel diagram]

Img = cv2.imread('test.jpg', 0) # The 0 argument is equivalent to: cv2.imread_grayscale. If 0 is not added, it will be read as a three-channel image by default, even if the original image looks like a grayscale image. Img = cv2.cvtcolor (img, cv2.color_rgb2gray) img = cv2.cvtcolor (img, cv2.color_rgb2gray) Img = image.open ('test.jpg').convert('L') # Convert to a binary Image (bit depth of 1, value of 0 or 1 per pixel)