The relationship between gamma and grayscale primarily involves the nonlinear adjustment of brightness (or grayscale) during image display or processing. Its core purpose is to make brightness changes perceived by the human eye more uniform and natural. The following is a detailed explanation:
1. Basic Concepts of Grayscale and Brightness
Grayscale: In digital images, grayscale represents the brightness level of a pixel, typically represented by integers between 0 (black) and 255 (white) (in 8-bit images). Intermediate values represent varying shades of gray.
Brightness: Physically, brightness is the intensity of light (unit: candela/square meter), but the human eye's perception of brightness is nonlinear—it is more sensitive to changes in dark areas and relatively insensitive to changes in bright areas.
2. Definition of Gamma
Gamma (γ) is a parameter used to describe nonlinear relationships. Its formula is:
Vout=Viny
Vin: Input signal (e.g., grayscale value, normalized to [0, 1]).
Vout: Output signal (adjusted grayscale value).
γ = 1: Linear relationship, with the output proportional to the input. γ > 1: Output values are compressed in dark areas and expanded in bright areas (compensating for the human eye's sensitivity to dark areas).
γ < 1: Output values are expanded in dark areas and compressed in bright areas (rarely used).
3. How does the gamma value affect grayscale?
Purpose: Adjusting the gamma value ensures that the image's grayscale distribution matches the human eye's perception. For example:
The original image's grayscale values may have a linear distribution, but the human eye may perceive the dark areas as too dark and the bright areas as too bright.
By applying gamma correction (e.g., γ = 2.2), the grayscale values in dark areas are boosted and the grayscale values in bright areas are lowered, resulting in a more natural overall appearance.
Example:
Input grayscale value: 0.1 (darker)
When γ = 2.2: 0.12.2 ≈0.0063 (the output is darker, but the human eye perceives it as "neutral"). When γ = 0.45 (reverse correction): 0.10.45≈0.398 (output brightens to compensate for the display device's gamma).
4. Application Scenarios of Gamma Correction
Display Devices: CRT monitors have a natural response curve of γ ≈ 2.5 due to physical characteristics, requiring reverse gamma correction (γ ≈ 1/2.5) to ensure normal image display. LCD/LED monitors also follow this standard.
Image Processing: In photography, gaming, or medical imaging, adjusting gamma can optimize detail visibility (for example, enhancing dark shadows or suppressing overexposed highlights).
File Formats: Color spaces such as sRGB have built-in gamma correction (γ ≈ 2.2) to ensure consistent image display across different devices.
5. Mathematical Relationship Summary
Forward Gamma (Encoding): Converts linear grayscale values to nonlinear signals to accommodate human perception or storage requirements.
Vencoded = Vlinear1/y

Reverse Gamma (Decoding): Converts nonlinear signals to linear grayscale values for display or analysis.

Typical value: In the sRGB standard, γ ≈ 2.2 (1/2.2 is used for encoding, 2.2 is used for decoding).
6. Intuitive Understanding
Low gamma (γ < 1): The image becomes brighter overall, with sharper shadow details, but may lose highlight details.
High gamma (γ > 1): The image becomes darker overall, with sharper highlight details, but shadows may appear completely black.
Example
Assuming the original grayscale values are [0, 0.25, 0.5, 0.75, 1]:
γ = 1: The output is the same as the input.
γ = 2.2: The output becomes [0, 0.063, 0.218, 0.466, 1], with shadows compressed and highlights expanded.
γ=0.45: The output becomes [0, 0.707, 0.841, 0.917, 1], with dark areas expanded and bright areas compressed.
By adjusting the gamma value, you can flexibly control the distribution of grayscale in the image, optimizing visual effects or adapting to specific needs.