PIXELBANKv8.2.1
Menu

Contrast Adjustment

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 α\alpha, to each pixel value, Iin(x,y)I_{in}(x,y).

Here are the steps to achieve contrast adjustment:

  1. Multiply each pixel value by the factor α\alpha.
  2. Apply a clamping operation to ensure the resulting pixel values fall within the valid range.
Iout(x,y)=clamp(αIin(x,y),0,255)I_{out}(x,y) = \text{clamp}(\alpha \cdot I_{in}(x,y), 0, 255)

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=150100 \times 1.5 = 150 and 200×1.5=300200 \times 1.5 = 300
  • Apply clamping to keep values within the valid range [0, 255]: 150150 stays 150150, but 300300 exceeds the maximum and clamps to 255255
  • The resulting output is [[150,255]][[150, 255]]

Constraints:

  • alpha > 0
  • Clamp output to [0, 255]
  • Round to nearest integer
Editor

Test Results

0/0
Run code to see test results.