Computer Vision Lab Algorithms Adjusting brightness and contrast

Adjusting brightness and contrast

A per-pixel linear transform that multiplies the intensity by a contrast factor and adds a brightness offset.

In the browserImage processingPoint processing

This content was prepared automatically from documented sources and its human scientific review is not yet complete. If you find an error, let us know.

Mathematical formula

g(x,y) = \operatorname{sat}\big(\lvert \alpha\, f(x,y) + \beta \rvert\big)

Explanation

Equivalent to convertScaleAbs in OpenCV: α greater than 1 increases the contrast, and a positive β brightens the image. The values are clipped to the range 0–255 (saturation), so details in very bright regions may be lost.

Detailed explanation

Intuition

The simplest image adjustment is a per-pixel linear transform: multiplying by \alpha stretches or compresses the range (contrast), and adding \beta shifts all the values (brightness). Because pixels are stored in eight bits, the result must be clipped to 0–255, and this is where most of the problems happen.

How it works step by step

  1. Choose \alpha>0 and\beta.
  2. Compute \alpha f + \beta for each pixel in floating point.
  3. Clip the result to the allowed range (saturation) and convert it to uint8.

Mathematical formulation

g = \min\big(255,\ \max(0,\ \alpha f + \beta)\big)

The transform preserves the order of intensities (a monotonic function), but when it clips values it merges everything above 255 into a single value, so the details are lost for good. The histogram shifts by \beta and stretches by \alpha.

Computational complexity

O(HW), and it can be implemented with a 256-value lookup table (LUT) because it depends only on the pixel value.

Advantages

  • Simple, and reversible as long as no clipping occurs.
  • Suitable for random data augmentation (color jitter).

Limitations

  • Saturation loses the details of bright or dark regions.
  • It does not adapt to the image content; an image with low contrast in only part of it needs local methods such as CLAHE.
  • Note: convertScaleAbs in OpenCV takes the absolute value before clipping.

When do you use it?

For quick correction and augmentation during training. If you want the “best contrast” automatically, use histogram stretching or equalisation.

Code example (Python + OpenCV)

import cv2
out = cv2.convertScaleAbs(img, alpha=1.3, beta=20)   # |1.3*img + 20| then clipped

Applications

Correcting dull images, preparing data, augmentation.

Limitations

It causes saturation and loss of detail at large values.

References

  1. OpenCV (2024).OpenCV documentation: Image Processing (imgproc module). docs.opencv.org. docs.opencv.org
  2. R. Szeliski (2022).Computer Vision: Algorithms and Applications (2nd ed.). Springer, Texts in Computer Science. doi:10.1007/978-3-030-34372-9

Experiments that use this algorithm

Related lessons

Try it in image processing