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 = L − 1 − r, where L = 256. This inverts intensities — dark becomes bright and vice versa. Useful for displaying X-rays or enhancing detail in dark areas.

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. Formula: s = c · log(1 + r), where c is a scaling constant. Great for images with large dynamic range (e.g. Fourier spectra).

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

Formula: s = 255 · (r / 255)^γ. When γ < 1, the image is brightened (expands dark values). When γ > 1, the image is darkened (compresses dark values). γ = 1 is the identity transformation.

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))