PIXELBANKv9.1.0
Menu

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: 64255β‰ˆ0.251\frac{64}{255} \approx 0.251, then 0.2510.5β‰ˆ0.5010.251^{0.5} \approx 0.501, and 255β‹…0.501β‰ˆ128255 \cdot 0.501 \approx 128.
  • For 128128: 128255β‰ˆ0.502\frac{128}{255} \approx 0.502, then 0.5020.5β‰ˆ0.7080.502^{0.5} \approx 0.708, and 255β‹…0.708β‰ˆ181255 \cdot 0.708 \approx 181.
  • Rounding these results gives the output [[128,181]][[128, 181]].

Constraints:

  • gamma > 0
  • Output rounded to nearest integer
solution.py

Test Results

0/0
Run code to see test results.