Today we are going to talk about the modes of image. The mode of image defines the depth and type of the pixel. These string values help you understand different information about the image. As of this writing, we have 11 standard modes.
1 (1-bit pixels, black and white, stored with one pixel per byte)
L (8-bit pixels, black and white)
P (8-bit pixels, mapped to any other mode using a color palette)
RGB (3x8-bit pixels, true color)
RGBA (4x8-bit pixels, true color with transparency mask)
CMYK (4x8-bit pixels, color separation)
YCbCr (3x8-bit pixels, color video format)
LAB (3x8-bit pixels, the Lab color space)
HSV (3x8-bit pixels, Hue, Saturation, Value color space)
I (32-bit signed integer pixels)
F (32-bit floating point pixels)
So, 1-bit pixel range from 0-1 and 8-bit pixel range from 0-255. The common modes are RGB, RGBA, P mode. Image also consist of band, common band like RGB for red, green, blue also have an Alpha(A) transparency, mainly for PNG image.
We can also change these modes with the help of convert or creating new image with the help of pillow library. Let see the code for example
# here we convert RGBA image to RGB image and painting the Alpha # trasparency band to white color image = Image.open("path/to/image") image.mode # this will tell image mode new_image = Image.new("RGB", image.size, (255, 255, 255)) new_image.paste(image, mask=image.split())
That's all about the modes. There is also raw modes where you can create even your modes, but will save that for another blog post :)