Lighting

# Lighting

## An example

Lighting effects are some of the most versatile and commonly used of all two-dimensional effects. By simply adjusting the contrast or brightness of an image, certain aspects can be easier to see. Imagine that you just took a picture of some stars through your new telescope, scanned it in, and are looking at it on your computer screen. It looks pretty good, except that most of the low intensity stars are not visible.
 Figure 1.1 Figure 1.2

All the picture really needs is a simple change of contrast, and maybe a small brightness adjustment. Separating the colors with the contrast, the dim stars look brighter, the dark looks darker, and you can see the small stars!!! If the image is too dark or bright for you, just alter the brightness, and it will look great.

In general, these effects are most important for photographs, which are often over or under exposed.

## How does it work?

Brightness and contrast work in different ways, but they are similar in the respect that they are both transfer functions. The brightness algorithm used by our applet, for example, re-maps the values of the red, green, and blue channels in the manner shown in figure 1.1. In the following equation, contrast is 100 minus the user-entered value divided by 100.

f(x)=( 1 - ( 1-x )contrast )( 1/contrast )

## How is that equation used?

This equation allows us to generate a map array, which has 256 elements. Each array element represents the value of the re-mapped pixel, so it is easy to later give pixels their re-mapped values. The approach of using a map with a complicated or mathematically time-consuming equation is not only beneficial from an ease-of-use standpoint, but also for the speed gained. Suppose that an algorithm uses a slow equation on millions of pixels. The performance would be terrible. If an array were used, however, the program could cache the answers ahead of time and only have to look at it in order to find the results.

Now for some interactive learning -- please visit the Java page: