Full search page →

Images as Arrays · Why does brightening make bright pixels dark?

BeginnerImages as ArraysImage lab

Description

Add the same number to every pixel of a real photo and compare 8-bit wraparound with saturating and floating-point arithmetic.

Try this: With the amount at 60 and the view on overflow, see where the red pixels sit. Now switch the arithmetic to saturate: the same pixels turn white instead of black, and the PSNR against the correct result becomes infinite. Last, set the amount to −100 with wraparound: which pixels flip, and in which direction?

Predict first

Add 60 to every pixel of an 8-bit photo: which pixels change the most?

Hints

The chapter section that uses this lab:

Explanation

Answer the prediction first, or open the explanation when you are ready.

Show the explanation

A byte cannot hold 256 or more, so any pixel at 196 or above overflows and starts again from 0. On this photo that is 27.2% of the pixels (17,855 of 65,536; the chapter counts 27.5% on the 512 × 512 original). Each of them falls by exactly 196 levels, from at least 196 to at most 59, while every other pixel rises by 60. The mean brightness even drops, from 129.1 to 119.3, although every pixel was asked to get brighter. With saturating or floating-point arithmetic the same pixels stop at 255 and the mean rises to 185.7.

Lab · Images as Arrays · Why does brightening make bright pixels dark?

Predict first

Add 60 to every pixel of an 8-bit photo: which pixels change the most?

Loading image…

Original photo (8-bit)
Your arithmetic (see Show)
Correct result: clip(pixel + amount, 0, 255)
Output value against input value

Try this: With the amount at 60 and the view on overflow, see where the red pixels sit. Now switch the arithmetic to saturate: the same pixels turn white instead of black, and the PSNR against the correct result becomes infinite. Last, set the amount to −100 with wraparound: which pixels flip, and in which direction?

Camera test image reduced to 256 × 256 by 2 × 2 averaging, so the fractions differ slightly from the chapter, which counts on the 512 × 512 original. The pixels are real bytes: wraparound is done in a Uint8Array, so the sum is reduced modulo 256 exactly as NumPy does for gray + np.uint8(60). Saturate clamps the integer sum to 0..255 (what cv2.add does); float adds in floating point, then clips and rounds, which gives the same bytes for whole-number amounts. A negative amount corresponds to subtracting. PSNR compares the result with the correct clipped result, with peak 255. Brightness here is the mean pixel value, 0 to 255; this shows arithmetic on stored values, not a physical exposure model.

Method and image sources

Open in the Playground →