These terms are used throughout:
An image band is a set of values, one per image pixel. Monochrome or grayscale images have one band; color images in the RGB system have three bands, CMYK images have four, and so on. Photoshop users will recognize bands as similar to Photoshop channels.
The mode of an image describes the way it represents colors. Each mode is represented by a string:
| Mode | Bands | Description |
|---|---|---|
"1" | 1 | Black and white (monochrome), one bit per pixel. |
"L" | 1 | Gray scale, one 8-bit byte per pixel. |
"P" | 1 |
Palette encoding: one byte per pixel, with a
palette of class ImagePalette
translating the pixels to colors. This mode is
experimental; refer to the online documentation.
|
"RGB" | 3 | True red-green-blue color, three bytes per pixel. |
"RGBA" | 4 |
True color with a transparency band, four bytes
per pixel, with the A channel
varying from 0 for transparent to 255 for opaque.
|
"CMYK" | 4 | Cyan-magenta-yellow-black color, four bytes per pixel. |
"YCbCr" | 3 | Color video format, three 8-bit pixels. |
"I" | 1 | 32-bit integer pixels. |
"F" | 1 | 32-bit float pixels. |
The sizes of objects in the image are described as a
2-tuple (, where
w,
h)h is the height in pixels and
w is the width.
The coordinates of a pixel are of its upper left corner.
Point (0,0) is the upper left corner of the image. The
x coordinate increases to the
right, and the y coordinate
increases downward.
When directions are given as compass points such as east or southwest, assume north is up, toward the top of the display.
Angles are given in degrees. Zero degrees is in the
+x (east) direction, and the
angle increases counterclockwise, in the usual Cartesian
convention. For example, angle 45 points northeast.
A bounding box or bbox is a
rectangle in the image. It is defined by a 4-tuple,
(x0,
y0,
x1,
y1)
where
(x0,
y0) is
the top left (northwest) corner of the rectangle, and
(x1,
y1) is
the bottom right (southeast) corner.
Generally, the area described by a bounding box will
include point
(x0,
y0),
but it will not include point
(x1,
y1) or
the row and column of pixels containing point
(x1,
y1).
For example, drawing an ellipse inside the bounding box
(0,0,5,10) will produce an ellipse 5
pixels wide and 10 pixels high. The resulting ellipse
will include pixel column 4 but not column 5, and will
also include pixel row 9 but not row 10.
You can specify colors in several different ways.
For single-band images, the color is the pixel value.
For example, in a mode "1" image, the
color is a single integer, 0 for black, 1 for white.
For mode "L", it is an integer in the
range [0,255], where 0 means black and 255 means
white.
For multi-band images, supply a tuple with one
value per band. In an "RGB"
image, the tuple (255,0,0)
is pure red.
You can use CSS-style color name strings of the form
#,
where rrggbb
specifies the red part as two hexadecimal digits,
rr
specifies green, and gg blue. For
example, bb"#ffff00" means yellow (full
red + full green).
To specify RGB pixel values in decimal, use a string
of the form "rgb(. For
example, R,G,B)""rgb(0,255,0)" is pure
green.
To specify RGB pixel values as percentages, use a
string of the form "rgb(. For
example, you can get a light gray with R%,G%,B%)""rgb(85%,85%,85%)".
To specify colors in the hue-saturation-lightness
(HSV) system, use a string of the form "hsl(.
H,S%,L%)"
is the
hue angle in degrees: 0 is red, 60 is yellow, 120 is
green, and so on.
H
is the
saturation: S0% for unsaturated (gray),
100% for fully saturated.
The lightness is L0% for
black, 50% for normal, and 100% for white.
For example, "hsl(180,100%,50%)" is
pure cyan.
On Unix systems, you can use any of the standard
color names from the locally installed set given in
file "/usr/lib/X11/rgb.txt",
such as "white", "DodgerBlue", or "coral".
Some operations that reduce the number of pixels, such as creating a thumbnail, can use different filters to compute the new pixel values. These include:
NEARESTUses the value of the nearest pixel.
BILINEARUses linear interpolation over a 2x2 set of adjacent pixels.
BICUBICUses cubic interpolation over a 4x4 set of pixels.
ANTIALIASNeighboring pixels are resampled to find the new pixel value.