Contrast Stretching using C++ and OpenCV: Image Processing

Theory

Contrast Stretching is one of the piecewise linear function. Contrast Stretching increases the dynamic range of the grey level in the image being processed.

Points (r1, s1) and (r2, s2) control the shape of the transformation. The selection of control points depends upon the types of image and varies from one image to another image. If r1 = s1 and r2 = s2 then the transformation is linear and this doesn’t affect the image. In other case we can calculate the intensity of output pixel, provided intensity of input pixel is x, as follows

for 0 <= x <= r1
output = s1 / r1 * x
for r1 < x <= r2
output = ((s2 – s1)/(r2 – r1))*(x – r1) + s1
for r2 < x <= L – 1
output = ((L-1 – s2)/(L-1 – r2))*(x – r2) + s2

Source Code

Output

r1 = 70 s1 = 0 r2 = 140 s2 = 255

 

SHARE Contrast Stretching using C++ and OpenCV: Image Processing

You may also like...

5 Responses

  1. Anonymous says:

    What are the factors to be considered while choosing r1,s1,r2,s2 values.(Since it varies from image to image,
    do we use the histogram plot to choose the r,s values?)

  2. Of course, histogram is one of the best way to choose these parameters.

  3. how to use header of opencv in c++ compiler like codeblocks?

  4. how to take values of r1 s1 r2 s2 from histogram

  5. how to choose the points r1,s1,r2,s2 from histogram plot

Leave a Reply

Your email address will not be published. Required fields are marked *

Share