This page is a part of CVprimer.com, a wiki devoted to computer vision. It focuses on low level computer vision, digital image analysis, and applications. It is designed as an online textbook but the exposition is informal. It geared towards software developers, especially beginners, and CS students. The wiki contains mathematics, algorithms, code examples, source code, compiled software, and some discussion. If you have any questions or suggestions, please contact me directly.

# Contrast

Consider an object in a gray scale image. Its contrast measures how different it is from its background [1]. Simply put it's the difference between the max gray level and min gray level of the object. More precise definition is below.

```Contrast of a dark object
= highest gray level adjacent to it - lowest gray level within it
Contrast of a light object
= highest gray level within it - lowest gray level adjacent to it
```

For example, the intensity of object #12 is 192 and that of the rest of #11 is 128. Therefore, the contrast of object #12 = 192 - 128 = 64.

The following is a more compact formula:

```Contrast = | border's intensity - object's intensity |
```

The object.

Suppose the curve on the left is the gray level function of the image. Then the tip marked with a horizontal line corresponds to an object. Finally, the height marked in red is the contrast of the object.

The images below show how the number of objects declines as the contrast threshold increases: 0, 30, 50, 70, 125.

Objects start to become visible to the human eye at contrast 5-10.

If we take the average intensity within the object instead of max/min we have the average contrast. The advantage of average contrast is that it is more 'robust'. Adding a single white pixel to a light object may dramatically increase its contrast, but not its average contrast.

The original
Photoshop: Auto Contrast
Pixcavator: contrast at 0 (othervise nothing is found)

Below a very good segmentation is found without limitations on size.

The original
Pixcavator: size = 0, contrast = 64

Exercise. Analyze the image above.

The contrast is used for filtering objects in Pixcavator and it also appears in its output table. Download the free Pixcavator Student Edition here.

For other measurements see Measuring objects.