Contrast Stretching

samir khanal
2 min readJun 5, 2020

Contrast stretching is an Image Enhancement method which attempts to improve an image by stretching the range of intensity values.

Here, we stretch the minimum and maximum intensity values present to the possible minimum and maximum intensity values.

Example: If the minimum intensity value(r min ) present in the image is 100 then it is stretched to the possible minimum intensity value 0. Likewise, if the maximum intensity value(r max) is less than the possible maximum intensity value 255 then it is stretched out to 255.(0–255 is taken as standard minimum and maximum intensity values for 8-bit images)

Note: Contrast stretching is only possible if minimum intensity value and maximum intensity value are not equal to the possible minimum and maximum intensity values. Otherwise, the image generated after contrast stretching will be the same as input image.

General Formula for Contrast Stretching:

For I min = 0 and I max = 255 (for standard 8-bit grayscale image)

where,

r = current pixel intensity value

r min = minimum intensity value present in the whole image

r max = maximum intensity value present in the whole image

Note: Output intensity value s should be rounded up to nearest integer value.

Output Example:

Input Image before Contrast Stretching with its histogram
Input Image after Contrast Stretching with its histogram

--

--