PIXELBANKv8.2.1
Menu

Gamma Correction

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:
  • First, apply the formula Iout=255(Iin255)0.5I_{out} = 255 \cdot \left(\frac{I_{in}}{255}\right)^{0.5} to each pixel value in [[64,128]][[64, 128]].
  • For 6464: 642550.251\frac{64}{255} \approx 0.251, then 0.2510.50.5010.251^{0.5} \approx 0.501, and 2550.501128255 \cdot 0.501 \approx 128.
  • For 128128: 1282550.502\frac{128}{255} \approx 0.502, then 0.5020.50.7080.502^{0.5} \approx 0.708, and 2550.708181255 \cdot 0.708 \approx 181.
  • Rounding these results gives the output [[128,181]][[128, 181]].

Constraints:

  • gamma > 0
  • Output rounded to nearest integer
Editor

Test Results

0/0
Run code to see test results.