Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint


Pixels are the basic building blocks of a digital image. A pixel is what we call the color or light values that occupy a specific place in an image. Think of an image as a big grid, with each square in the grid containing one color or pixel. This grid is sometimes called a bitmap. An image with a resolution of 1024×768 is a grid with 1,024 columns and 768 rows, which therefore contains 1,024 × 768 = 786,432 pixels. Knowing how many pixels are in an image does not indicate the physical dimensions of the image. That is to say, one pixel does not equate to one millimeter, one micrometer, or one nanometer. Instead, how “large” a pixel is will depend on the pixels per inch (PPI) setting for that image.

Each pixel is represented by a number or a set of numbers—and the range of these numbers is called the color depth or bit depth. In other words, the color depth indicates the maximum number of potential colors that can be used in an image. An 8-bit color depth uses the numbers 0-255 (or an 8-bit byte) for each color channel in a pixel. This means a 1024×768 image with a single channel (black and white) 8-bit color depth would create a 768 kB image. Most images today use 24-bit color or higher, allowing three 0-255 numbers per channel. This increased amount of data about the color of each pixel means a 1024×768 image would take 2.25 MB. As a result of these substantial memory requirements, most image file formats do not store pixel-by-pixel color information. Image files such as GIF, PNG, and JPEG use different forms of compression to more efficiently represent images.

Most pixels come in two flavors: grayscale and color. In a grayscale image, each pixel has only a single value representing the light value, with zero being black and 255 being white. Most color pixels have three values representing red, green, and blue (RGB). Other non-RGB representation schemes exist, but RGB is the most popular format. The three colors are each represented by one byte, or a value from 0 to 255, which indicates the amount of the given color. These are usually combined into an RGB triplet in a (red, green, blue) format. For example, (125, 0, 125) means that the pixel has some red, no green, and some blue, representing a shade of purple. Some other common examples include:

  • Red: (255, 0, 0)

  • Green: (0, 255, 0)

  • Blue: (0, 0, 255)

  • Yellow: (255, 255, 0)

  • Brown: (165, 42, 42)

  • Orange: (255, 165, 0)

  • Black: (0, 0, 0)

  • White: (255, 255, 255)

Remembering those codes can be somewhat difficult. To simplify this, the Color class includes a host of predefined colors. For example, to use the color teal, rather than needing to know that it is RGB (0, 128, 128), simply use:

from SimpleCV import Color

# An easy way to get the RGB triplet values for the color teal.
myPixel = Color.TEAL

Similarly, to look up the RGB values for a known color:

from SimpleCV import Color

# Prints (0, 128, 128)
print Color.TEAL

Notice the convention that all the color names are written in all CAPS. To get green, use Color.GREEN. To get red, use Color.RED. Most of the standard colors are available. For those readers who would not otherwise guess that Color.PUCE is a built-in color—it’s a shade of red—simply type help Color at the SimpleCV shell prompt, and it will list all available colors. Many functions include a color parameter, and color is an important tool for segmenting images. It would be worthwhile to take a moment and review the predefined color codes provided by the SimpleCV framework.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint