📘
Gamma Correction
MediumImage 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:
- Normalize the input image intensity values to the range [0,1].
- Raise each normalized value to the power of gamma.
- Scale the result back to the original range [0,255].
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⋅(255Iin)0.5 to each pixel value in [[64,128]].
- For 64: 25564≈0.251, then 0.2510.5≈0.501, and 255⋅0.501≈128.
- For 128: 255128≈0.502, then 0.5020.5≈0.708, and 255⋅0.708≈181.
- Rounding these results gives the output [[128,181]].
Constraints:
- gamma > 0
- Output rounded to nearest integer
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.