📘
Contrast Adjustment
EasyImage Processing
Implement a point operator to adjust the contrast of an image by modifying its pixel values. This task involves applying a simple transformation to each pixel in the image.
The concept of contrast adjustment is fundamental in image processing, as it enables the enhancement or reduction of the difference between various regions in an image, making it more visually appealing or suitable for further analysis. The contrast of an image can be adjusted by applying a multiplication factor, denoted as α, to each pixel value, Iin(x,y).
Here are the steps to achieve contrast adjustment:
- Multiply each pixel value by the factor α.
- Apply a clamping operation to ensure the resulting pixel values fall within the valid range.
This technique is widely used in digital photography and image editing software.
Example:
Input:
adjust_contrast([[100, 200]], 1.5)
Output:
[[150, 255]]
Reasoning:
- For each pixel, multiply by the contrast factor: 100×1.5=150 and 200×1.5=300
- Apply clamping to keep values within the valid range [0, 255]: 150 stays 150, but 300 exceeds the maximum and clamps to 255
- The resulting output is [[150,255]]
Constraints:
- alpha > 0
- Clamp output to [0, 255]
- Round to nearest integer
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.