v9.1.1
Menu

Gamma Correction

mediumFREEPoint OperatorsImage ProcessingCV: Image Processing

Implement a point operator to apply gamma correction to an image. This process transforms the image's intensity values to adjust its brightness and contrast.

Gamma correction is a non-linear operation that modifies the image's pixel values based on a power-law relationship, which can brighten or darken regions. The gamma value determines the amount of correction, where values less than 1 increase the brightness of dark areas and values greater than 1 decrease the brightness.

Here are the steps to perform gamma correction:

  1. Normalize the input image intensity values to the range [0,1].
  2. Raise each normalized value to the power of gamma.
  3. Scale the result back to the original range [0,255].
Iout=255⋅(Iin255)γI_{out} = 255 \cdot \left(\frac{I_{in}}{255}\right)^\gamma

This technique is widely used in image and video processing applications to adjust the display's brightness and contrast.

Example

Input
gamma_correct([[64, 128]], 0.5)
Output
[[128, 181]]
Reasoning
  • Input: image is a 1×21 \times 2 grid of 8-bit intensities, 6464 (dark grey) and 128128 (mid grey), and gamma is γ=0.5\gamma = 0.5.
  • Normalize: dividing by 255255 maps each pixel into [0,1][0,1]: 64255≈0.2510\frac{64}{255} \approx 0.2510 and 128255≈0.5020\frac{128}{255} \approx 0.5020.
  • Apply the power: with γ=0.5\gamma = 0.5 the power is a square root: 0.25100.5≈0.50100.2510^{0.5} \approx 0.5010 and 0.50200.5≈0.70850.5020^{0.5} \approx 0.7085. Because both values lie below 11, an exponent below 11 pushes them up.
  • Scale back: 255⋅0.5010≈127.75255 \cdot 0.5010 \approx 127.75 and 255⋅0.7085≈180.67255 \cdot 0.7085 \approx 180.67, which round to the nearest integers 128128 and 181181, giving [[128, 181]].
  • Notice: the dark pixel roughly doubled (64→12864 \to 128) while the mid-grey one gained only about 41%41\%, so γ<1\gamma < 1 lifts shadows most. The endpoints never move, since 0γ=00^\gamma = 0 and 1γ=11^\gamma = 1, so 00 and 255255 stay fixed for any γ\gamma. With γ=1\gamma = 1 the image is unchanged.

Constraints

  • gamma > 0
  • Output rounded to nearest integer

Learn this in

More from CV: Image Processing

solution.py

Test results

Sign in to run your code against the test cases.