AI Glossary / Computer vision and multimodal AI / Advanced
Contrast stretching
Definition
Contrast stretching remaps an image's intensity values so a selected input interval occupies a desired output interval. In a linear stretch, values between lower and upper input limits are mapped proportionally. Values outside those limits are commonly clipped. The purpose is to increase useful tonal separation in the displayed or processed image.
What it means
Suppose a grayscale photograph contains values concentrated in a small middle portion of the available range. Expanding that portion can make differences more visible. The important choice is which interval to expand. Using the absolute minimum and maximum preserves all in-range distinctions in principle, but a few extreme pixels may determine an unhelpful stretch. Percentile-based limits deliberately ignore some extremes. Neither choice creates new captured information, and a display enhancement should not be confused with a change in the underlying scene or measurement.
How it works
Choose input limits L and H and output limits A and B. For L<H, an interior value x maps to A+(x−L)(B−A)/(H−L). Define clipping and rounding outside and within the output range. Limits may be fixed for a collection or estimated per image, for example using percentiles. The mapping then acts on each pixel. Different channel strategies can alter color appearance. Contrast stretching differs from histogram equalization, which uses the cumulative intensity distribution to produce a generally nonlinear mapping.
Three practical examples
- An archive worker creates a readable display copy of a faded scan while keeping the original data and recording the applied limits.
- A vision team compares fixed and image-specific stretches before a recognition pipeline, checking whether either helps on representative held-out images.
- A photographer tests a percentile stretch on a flat scene, inspecting whether bright reflections or dark details are discarded by the chosen limits.
Think of it this way
Imagine enlarging one interval on a ruler so its markings occupy a longer line. Differences within that interval become easier to distinguish. Markings outside the chosen interval may be pushed to the endpoints and lose their individual positions. This is why the stretch limits are substantive choices, not just cosmetic settings. Enlarging the markings cannot reveal a measurement that the original ruler never recorded, and every image need not benefit from the same interval.
Worked example
In an original 8-bit grayscale example, select input limits L=60 and H=180 and output limits A=0 and B=255. Input 60 maps to zero, 120 maps to 127.5 before rounding, and 180 maps to 255. Input 30 clips to zero under the stated rule, while 220 clips to 255. The interior gain is 255/120=2.125. If two pixels originally had values 20 and 40, both become zero, so their difference is lost. This example shows expansion and clipping together. It does not prescribe suitable limits for an actual photograph; those depend on its content, intended use and data representation.
Illustrative case study
A fictional equipment-documentation team prepares a set of old grayscale diagrams for a searchable manual. An automatic stretch makes many diagrams easier to view, but a few scans contain dark borders that dominate their minimum values. The team compares a percentile-based option and finds that some faint annotations then disappear at the output extremes. Reviewers therefore inspect difficult pages and retain both the original scan and the approved viewing copy. The team evaluates readability at the intended page size rather than assuming that a wider histogram guarantees a better document. This is an illustrative workflow, not a measured study result.
Common misconceptions and mistakes
Stretching a histogram does not guarantee better visibility of every feature. A few outliers can dominate minimum - maximum limits, while percentile limits can remove meaningful extremes. Another mistake is independently stretching frames in a video and overlooking brightness fluctuations between them. If the input is constant so H=L, the formula needs explicit special handling rather than division by zero. Separately stretching color channels can change their relationships. Finally, image-specific normalization can erase meaningful differences between images when absolute intensity is part of the intended analysis.
Business use
Contrast stretching can support document preparation, visual review and image-processing experiments. A repeatable business workflow should record how limits are selected and distinguish viewing copies from source records. If a collection must be compared quantitatively, check whether independent stretches undermine that comparison. For machine-learning use, test the transformation as part of the complete pipeline and monitor whether new images fall outside the expected range. The relevant success criterion is improved performance on the intended task, not simply an image that uses more of its available intensity range.
People also ask
Is stretching the same as histogram equalization?
No. Linear stretching maps a selected interval proportionally; equalization uses the intensity distribution's cumulative structure.
Why use percentiles?
They can reduce the influence of rare extreme values, at the cost of deliberately clipping some data.
Can the original values always be recovered?
No. Clipping and rounding can discard distinctions, so retain original data when recovery matters.
Check your understanding
Why did input 120 map near the middle of the output range?
Answer: It was halfway between 60 and 180.
Why did values 20 and 40 become identical?
Answer: Both lay below the lower limit and were clipped.
What happens when both input limits are equal?
Answer: The stated formula is undefined and needs a specified alternative behavior.
Related terms
- Histogram
- Clipping
- Point (range) operation
- Histogram equalization
- Dynamic range
- Intensity normalization
- point operation
Learn next
Compute a stretch for a short list containing one extreme outlier. Compare minimum - maximum limits with chosen percentile limits and count the clipped values. Then consider whether a collection needs one consistent mapping or separate display adjustments for each image.
More in Computer vision and multimodal AI
- Content-based image retrieval - Content-based image retrieval, or CBIR, finds images using information extracted from their visual content.
- Content-preserving warp - A content-preserving warp is a spatially varying image transformation that balances desired movement against distortion of visible structures.
- Context encoders - Context encoders are neural networks trained to predict missing image regions from the surrounding visible content.
- Contrast-detection autofocus - Contrast-detection autofocus adjusts a camera's focus using image-derived contrast or sharpness measurements.
- Contrast (point operation) - Contrast as a point operation changes the separation between pixel values by applying a tone mapping independently at each image location.
- Contrast sensitivity function (CSF) - A contrast sensitivity function describes how sensitivity to visual contrast varies with properties such as spatial frequency under specified viewing...
Sources
MathWorks, imadjust: https://www.mathworks.com/help/images/ref/imadjust.html MathWorks, Specify Contrast Adjustment Limits: https://www.mathworks.com/help/images/specify-adjustment-limits-as-range.html The grayscale values, ruler analogy and documentation-team case are original educational illustrations. Software defaults should be checked in the applicable version rather than assumed universal.
Previous: Contrast set learning Next: Contrastive divergence