Looking through PIL (and related to this question), where can I get a comprehensive list of Image modes? I see "RGB", "RGBX", my code has "BGRX" somehow even though it's not mentioned in the PIL docs that I can see. How can I see which is which, what PIL supports, and what proper modes to select when interacting with windows API calls, for example?
Basically I know very little about image modes and would like to learn more than just what letters to put in to make it magically work.
An image mode determines the number of colors that can be displayed in an image and can also affect the file size of the image. Photoshop Elements provides four image modes: RGB, bitmap, grayscale, and indexed color. Image modes.
If you have a P mode image, that means it is palettised. That means there is a palette with up to 256 different colours in it, and instead of storing 3 bytes for R, G and B for each pixel, you store 1 byte which is the index into the palette. This confers both advantages and disadvantages.
fromarray - Function. 1.1.1 Construct a CASA image from a numerical (integer or float) array. This function converts a numerical (integer or float) numpy array of any size and dimensionality into a CASA image. It will create both float and complex valued images.
RGB is a very common color mode for digital images. It uses 3 channels to represent color Red-Green-Blue. It also works with image file types such as jpg and bpm. RGBA on the other hand is a color mode that can represent “transparency” through its Alpha channel.
There are two distinct concepts in Pillow, with confusingly similar names:
These are listed at https://pillow.readthedocs.io/en/latest/handbook/concepts.html#modes.
Per those docs:
The mode of an image defines the type and depth of a pixel in the image.
This kind of "mode" is what is exposed through an Image
's .mode
attribute, can be changed through the .convert()
method, and can be passed to methods that take a mode
parameter. They are not the same as "raw modes".
These are used internally by the raw decoder, which converts uncompressed data from an image file into a format that a PIL Image
object can understand. There are several times more "raw modes" than "modes", and they convey information about not only the type (colored or grayscale) and bit depth of pixels in an image, but also their layout in the file. For example, raw mode RGB;L
is documented as meaning "24-bit true colour, line interleaved (first all red pixels, then all green pixels, finally all blue pixels)."
As noted in the docs linked above (and also in the old PIL documentation), a list of raw modes can be found in Unpack.c
. You'll find the list near the end of the file.
Unpack.c
from the current master branch of Pillow: https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Unpack.c
Unpack.c
from the final release of PIL: http://svn.effbot.org/public/tags/pil-1.1.7/libImaging/Unpack.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With