## Chapter 4. Point operations

He told him, point for point, in short and plain.

--Chaucher

The simplest image filters are point operations, where the new value of a pixel are only determined by the original value of that single pixel alone.

## Threshold

Thresholding an image is the process of making all pixels above a certain threshold level white, others black.

Note In Figure 4.1, “threshold” and other examples for point operations, there is more code than strictly neccesary to implement the effect. The additional structuring and modularization of the code is meant to make the actual transformation of the pixel values easier to see seperated from the loops and details of dealing with the pixel data.

## Brightness

When changing the brightness of an image, a constant is added or subtracted from the luminnance of all sample values. This is equivalent to shifting the contents of the histogram left (subtraction) or right (addition).

`new_value = old_value + brightness`

The goal of the code in Figure 4.2, “brightness” is to add a constant amount of light to the sample value in each position in the image raster.

## Contrast

Changing the contrast of an image, changes the range of luminance values present. Visualized in the histogram it is equivalent to expanding or compressing the histogram around the midpoint value. Mathematically it is expressed as:

`new_value = (old_value - 0.5) × contrast + 0.5`

The subtraction and addition of 0.5 is to center the expansion/compression of the range around 50% gray.

Specifying a value above 1.0 will increase the contrast by making bright samples brighter and dark samples darker thus expanding on the range used. While a value below 1.0 will do the opposite and reduce use a smaller range of sample values.

## Brightness + Contrast

It is common to bundle brightness and control in a single operations, the mathematical formula then becomes:

`new_value = (old_value - 0.5) × contrast + 0.5 + brightness`

## Invert

Inverting the sample values in the image, produces the same image that would be found in a film negative. Figure 4.6, “invert”

## Gamma

A CRT monitor doesn't have a linear correspondence between the voltage sent to the electron guns and the brightness shown. The relationship is closely modelled by a powerfunction i.e. display_intensity=pixel_valuegamma. To correct an image for display, assuming the monitor doesn't already have global corrections in place. Will involve applying the function new_value=old_value1.0-gamma.

## Levels

The levels tool found in many image processing packages is in it's simplest form just a different way to adjust brightness/ contrast.

The parameters found in levels tools are in the order of spatial placement in dialogs like Figure 4.8, “The GIMP's levels tool”:

• input blacklevel
• input whitelevel
• output blacklevel
• output whitelevel
• gamma correction

## Curves

The view is a plot of the function f(x) of the transform applied, this means that the darkest values in the image are on rthe left, and the brightest on the right. The resulting value for an original value is the y value.

A diagnoal line from lower left to upper right indicates no transformation.

A horizontal line, means all pixels get the same value, along the bottom black, and along the top white.

The transform indicated in Figure 4.10, “The GIMP's curves tool” makes most values in the image darker, but allocates a larger portion of the values available to the brightest portion of the scale. This could be used to see more detail in for instance the sky in a photograph.

### Lookup tables

As can be observed in the code examples given in this chapter, there is direct mapping between input pixel values and output pixel values for point process operations.

When dealing with 8bit images, the number of input and output values are greatly reduced, if the processing taking place within the transform is expensive, having a precalculated table for all input values is a common optimizations, this is called a LookUpTable (LUT).

When the sample values stored are 16bit the advantage of a lookup table is still present since the number of entries is 65536, but when moving to 32bit floating point, the number of precalculated values needed is exceedingly large.

## Excercises

These exercies are not just exercies for the point operation topic, but intended as initial experiments with the gluas framework.

### 1. Exchange Red and Green

Write a gluas program that exchanges the red and green component of all pixels in an image.

Is this a point operation?

### 2. Value boost

Create a program performing the transformation in Figure 4.10, “The GIMP's curves tool”.

### 3. Checkerboard

Create a program that draws a 8x8 checker board on top of the existing image. The checker board should be black and white, square, cover as large area as possible and be centered on the image.

### 4. Position dependent contrast

Create a program that has a linearly increasing contrast applied to it. So that the leftmost column of the raster has a contrast of 0.0 applied to it, and the rightmost column of the raster has a contrast of 2.0 applied to it.

Is this a point operation?