Getting Started with Image Processing

I have been working on digital image processing for sometime now, and I was learning a lot of stuff recently. I thought I should put together a very basic getting started guide on image processing, which could help a lot of enthusiasts. This aritcle is greatly borrowed from the Image Processing - 101 Sher Minn Chong. This article, as I have planned, will be multi-part, and will be as detail as possible from my own understanding of the concepts.

Digital Image

Digital images are fundamentally a finite number of pixels distributed in X and Y axis, and are stored on the disk as a two (or more) dimentional array of integers or more complex datastructers, in rows and columns. Any 2D digital image can be viewed as a matrix of size NxM. Each element in the matrix represents a pixel. A pixel, and its definition, and how a pixel is displayed on a screen or even how it is printed on a paper, are out of the context of this article. Following is a hypothetical representation of a flower as a digital image.

There are a few points to be noted here.

Now, if you think about it, an absolute minimum palette should have at least two colors in it. Suppose my palette of colors have only black and white. Here is an image, that I can represent using this palette.

Now, for indexing two colors, we need a minimum of one-bit of storage. If the bit is 0 —> the color is black, and if it is 1 —> the color is white. Such images are commonly referred to as monochrome images. Every pixel in a monochrome image is either 1 or 0.

But what if I need more colors to realistically reproduce an image? Basically, I need more bits to represent each pixel. That’s it! Suppose instead of just 1 bit, I use 2 bits to represent each pixel. I can now show 4 different colors. Take a look at my new palette.

00 --> Black
01 --> Dark Gray
10 --> Light Gray
11 --> White

Note : You don’t have to limit your palette to shades of gray only. I can use any four colors to build my palette. We will cover such palettes down the line. I just use these colours for simplicity sake.

Now, just by adding one more bit, I have gratly improved the quality of the image. The image below shows the difference.

The number of bits used to represent a pixel is called the bit depth or color depth in digital image processing. Most images we now find on the web has 8-bit or higher depth. Using just 8 bits, you can display 256 different colors.

Multi-Channel Images (Color Images)

So far we have discussed only single channel indexed images, where each pixel in the image is represented by a single number. This brings one limitation as the number of shades (or colors basically) we want to have in an image increases. Suppose you have an image with some pixels with colors wide apart in the spectrum of colors. This will cause a memory access problem since the direct address space need to display an image on a screen will be large. The concept of planar graphics brings a solution to this problem. Each image is represented as multiple planes. Each plane would represent a part of the pixel data (and not the entire pixel data).

Color Models

There are various methods to make use of the planar model of graphics. One is to adopt the physical nature of light and colours. There are three primary colours in nature, namely Red, Green and Blue. All other colours are basically composition of these three colours by various amounts. For example Red and Green without blue will give us Yellow. This concept brings us a RGB colour model, where each plane will represent either the Red, Green or Blue component of the image.

Mode 13h

While this is an unrelated topic, I think this is worth mentioning about the non-planar graphics mode in VGA. The VGA hardware included a special graphics mode where each pixel drawn on the screen was represented by 8-bits in the graphics memory. There were 256 indexed predefined colors in the palette, and this mode was enabled when the AL value is 0x13 and AH value is 0x00 and BIOS interrupt 10h is executed. Even before this, BBC Micro had a smaller palette of 8 colors using its 3-bit color graphics adapter. Read more about different color depths here. The default 256-color VGA palette is shown below.