|
A common way to store and manipulate color images digitally is as an array (or matrix) of vectors. The vectors are a list of three numbers from zero to 255 that represents how bright the red, green, and blue components of the color are. For example, the following is how a single blue-green pixel surrounded by eight black pixels would be represented.  |
| (0,0,0) | (0,0,0) | (0,0,0) |
| (0,0,0) | (0,128,128) | (0,0,0) |
| (0,0,0) | (0,0,0) | (0,0,0) |
|
Keep in mind that light mixes together differently than pigment: two colors mixed together become brighter than either, sometimes in unexpected ways. So while blue and green do mix together to make a brighter blue-green, red and green mix to make yellow (0 , 255 , 255), and all three mix to make white (255 , 255 , 255).
When changing an image it is often easier to deal with each of these three colors seperately. So we can seperate the image into three arrays (called channels) that have a single value at each position. The array above then becomes:
Converting an image to numbers allows us to use mathematical operations to change the image in various ways. The simple picture to the left, below, shows an image with only green pixels, so only one channel is necessary. Next to that is a table representing the intensity of green light in each pixel. To the far right below is an example of a higher resolution color illustration. In each of the examples below, a similar operation is performed on the simple green image and the illustration. |
 |
| 120 | 180 | 120 |
| 180 | 235 | 180 |
| 120 | 180 | 120 |
|  |
To brighten the image, we add the same number to each value in all three arrays. |
 |
| 140 | 200 | 140 |
| 200 | 255 | 200 |
| 140 | 200 | 140 |
|  |
To darken it, we subtract. |
 |
| 80 | 120 | 80 |
| 120 | 195 | 120 |
| 80 | 120 | 80 |
|  |
To increase the contrast, we multiply everything by some factor. |
 |
| 137 | 237 | 137 |
| 237 | 255 | 237 |
| 137 | 237 | 137 |
|  |
To decrease contrast, we divide. (Usually we would also add the same amount to each pixel as well so that the image would tend towards a uniform gray low-contrast image rather than a uniform black image. This has been done to the illustration.) |
 |
| 60 | 90 | 60 |
| 90 | 118 | 90 |
| 60 | 90 | 60 |
|  |
To create a photographic negative effect, we replace each value x with (255 - x). |
 |
| 175 | 135 | 175 |
| 135 | 20 | 135 |
| 175 | 135 | 175 |
|  |
To create some static or noise, add a random number to each value. |
 |
| 95 | 131 | 71 |
| 213 | 138 | 214 |
| 164 | 170 | 146 |
|  |
If we take the difference between each pair of neighboring pixels and create a new array of those differences, only edges will show up. This is used for computer vision applications. |
 | |  |
If we double the width and height of an image, it has four times as many pixels as before. The simplest way to fill all these new pixels in is to simply copy each original pixel four times, making squares of four identical pixels. The trouble with this is that even though individual pixels are small enough that they run together, a picture made up of blocks of four pixels looks jagged. To get a smoother effect, we need to be able to find a reasonable value between (interpolate) two neighboring pixels. One simple way to do this is to use a weighted average of the two nearest neighbors to the point we want to find. This is called linear interpolation. (Since it is done in both the x and y directions we call it bilinear interpolation.) This works fairly well, but it can be improved further by using the value of three neighboring points and fitting a polynomial to them. This is called bicubic interpolation. Using bicubic interpolation allows us to enlarge an image without getting all those "jaggies" from large square pixels. But it still isn't great: although we have eliminated the jaggies, new problems have appeared: it looks blurry and the edges have ghostly outlines around them, which is called "ringing."
|
There are more advanced interpolation methods that get better results. When I created the image to the left using Photoshop's painting tools, my computer had only 16 MB of memory, and my screen resolution was 640 x 480. These restrictions made it impractical to create large, high resolution images. But as technology improved, I regretted that the image was so small. When printed at a decent resolution, it was only an inch wide.
Fortunately, a new method of enlarging images created exactly the results I wanted. It's called Xin Li's New Edge-Directed Interpolation. It works by smoothing an image as it enlarges it, but smoothing in a way that follows the color contours and edges within the image. The effect is something like an artist's brush strokes. Click on the picture to see the enlarged image, followed by the original resized with no interpolation for comparison.
|