While brightness adjustment shifts the overall intensity level of an image up or down, contrast adjustment deals with the difference between the intensity levels. Think of contrast as the degree of separation between the darker and lighter areas in an image. High contrast images have stark differences (deep blacks, bright whites), while low contrast images appear washed out or murky, with intensities clustered together.
Adjusting contrast is a fundamental technique used to make image features more distinct and visually appealing. Increasing contrast can help highlight details that might be lost in areas with similar brightness levels. Decreasing contrast can sometimes be useful to soften an image or prepare it for specific types of analysis where large intensity variations are problematic.
The most common way to adjust contrast is through a linear transformation, often called contrast stretching. Similar to brightness adjustment, this is a point operation, meaning each pixel's value is modified independently based on its original value.
The core idea is to scale the difference between a pixel's intensity and some reference level (often the mid-level gray, like 128 for an 8-bit image). We multiply the pixel's value by a factor, often denoted by alpha (α), which acts as a gain or slope.
A general formula combining brightness and contrast adjustment looks like this:
pout=α⋅pin+β
Where:
For purely adjusting contrast, we focus on the α factor:
We can visualize the effect of the contrast factor α by plotting the output pixel value against the input pixel value. The formula pout=α⋅pin+β describes a line. The slope of this line is determined by α. A steeper slope means higher contrast.
The plot shows how different contrast factors (α) change the transformation applied to pixel values. A steeper slope (α>1, blue line) stretches the intensity range, increasing contrast. A shallower slope (0<α<1, orange line) compresses the range, decreasing contrast. The dashed gray line represents no change (α=1). Note that the exact output values also depend on the brightness offset β, and the results shown are before applying clipping.
Just like with brightness adjustment, applying a contrast transformation can result in calculated pixel values (pout) that fall outside the valid range for standard image formats (typically [0, 255] for 8-bit grayscale or color channels).
For example, increasing contrast (α>1) might push originally dark values below 0 or originally bright values above 255. Decreasing contrast (α<1) might map the entire original range into a smaller sub-range within [0, 255].
To handle this, we need to clip or saturate the results. Any calculated value below 0 is set to 0, and any value above 255 is set to 255.
pout,clipped=max(0,min(255,pout))
This ensures all final pixel values remain within the valid displayable range. However, be aware that clipping can lead to a loss of detail in the very dark or very bright regions of the adjusted image, as multiple distinct input values might get mapped to the same output value (0 or 255).
Contrast adjustment, especially when combined with brightness control using the pout=α⋅pin+β formula, provides a simple yet powerful way to modify the look and feel of an image, often serving as an important preprocessing step before more complex computer vision tasks.
© 2025 ApX Machine Learning