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:
|1||Black and white (monochrome), one bit per pixel.|
|1||Gray scale, one 8-bit byte per pixel.|
Palette encoding: one byte per pixel, with a
palette of class |
|3||True red-green-blue color, three bytes per pixel.|
True color with a transparency band, four bytes
per pixel, with the |
|4||Cyan-magenta-yellow-black color, four bytes per pixel.|
|3||Color video format, three 8-bit pixels.|
|1||32-bit integer pixels.|
|1||32-bit float pixels.|
The sizes of objects in the image are described as a
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
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,
the top left (northwest) corner of the rectangle, and
the bottom right (southeast) corner.
Generally, the area described by a bounding box will
but it will not include point
the row and column of pixels containing point
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.
"L", it is an integer in the
range [0,255], where 0 means black and 255 means
For multi-band images, supply a tuple with one
value per band. In an
image, the tuple
is pure red.
You can use CSS-style color name strings of the form
specifies the red part as two hexadecimal digits,
specifies green, and
"#ffff00" means yellow (full
red + full green).
To specify RGB pixel values in decimal, use a string
of the form
"rgb(0,255,0)" is pure
To specify RGB pixel values as percentages, use a
string of the form
example, you can get a light gray with
To specify colors in the hue-saturation-lightness
(HSV) system, use a string of the form
hue angle in degrees: 0 is red, 60 is yellow, 120 is
green, and so on.
0% for unsaturated (gray),
100% for fully saturated.
50% for normal, and
100% for white.
On Unix systems, you can use any of the standard
color names from the locally installed set given in
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:
Uses the value of the nearest pixel.
Uses linear interpolation over a 2x2 set of adjacent pixels.
Uses cubic interpolation over a 4x4 set of pixels.
Neighboring pixels are resampled to find the new pixel value.