Learning/IVP/Session 03
Session 03📈

Intensity Transformations

Point-wise gray-level transformations: negative, logarithm, and power-law (gamma).


Learning Objectives

  • Apply negative transformation to invert intensity
  • Use logarithmic transform to expand dark regions
  • Apply power-law (gamma) transform to control brightness

Negative Transformation

The negative of an image is obtained by s=L1rs = L - 1 - r, where L=256L = 256. This inverts intensities — dark becomes bright and vice versa. Useful for displaying X-rays or enhancing detail in dark areas.

s=L1r(L=256)s = L - 1 - r \qquad (L = 256)
rr = original intensity, ss = transformed intensity
Ex3_1a — Negative transformationPython
import cv2
import numpy as np

img = cv2.cvtColor(cv2.imread('input.jpg'), cv2.COLOR_BGR2RGB)
L = 256
negative = (L - 1) - img

Logarithmic Transformation

The log transform maps a narrow range of dark input values into a wider range of output values, where cc is a scaling constant. Great for images with large dynamic range (e.g. Fourier spectra).

s=clog(1+r)s = c \cdot \log(1 + r)
c=255log(1+max(r))c = \dfrac{255}{\log(1 + \max(r))} is the usual choice, mapping the result into [0,255][0, 255]
Ex3_1b — Log transformationPython
img_f = img.astype(np.float64)
c = 255 / np.log(1 + np.max(img_f))
log_img = np.uint8(c * np.log(1 + img_f))

Power-Law (Gamma) Transformation

When γ<1\gamma < 1, the image is brightened (expands dark values). When γ>1\gamma > 1, the image is darkened (compresses dark values). γ=1\gamma = 1 is the identity transformation.

s=255(r255)γs = 255 \cdot \left(\frac{r}{255}\right)^{\gamma}
γ<1\gamma < 1 brightens · γ>1\gamma > 1 darkens · γ=1\gamma = 1 leaves the image unchanged
Ex3_1c — Power (gamma) transformationPython
img_f = img.astype(np.float64) / 255.0

gamma_values = [0.3, 0.5, 1.0, 2.0, 3.0]

for gamma in gamma_values:
    result = np.uint8(np.clip((img_f ** gamma) * 255, 0, 255))