User:Nehagode/Constrast Stretching

Contrast Stretching is a technique of image processing . It is an image enhancement technique that attempts to improve the contrast in an image by `stretching' the range of intensity values it contains to span a desired range of values, e.g. the the full range of pixel values that the image type concerned allows.[1]

How it Works edit

 

Before the stretching can be performed it is necessary to specify the upper and lower pixel value limits over which the image is to be normalized. Often these limits will just be the minimum and maximum pixel values that the image type concerned allows. For example, for 8-bit gray level images, the lower and upper limits might be 0 and 255. Call the lower and the upper limits a and b respectively.[1]

The simplest sort of normalization then scans the image to find the lowest and highest pixel values currently present in the image. Call these c and d. Then each pixel P is scaled using the following function:

 

[2]

Contrast Stretching in MATLAB edit

To apply linear contrast stretch to an image, we try to map our intensities [xmin, xmax] in image pixels 0 to 255 range which is done by our function histogramlinear. This function will receive the image that we are trying to do contrast stretching on. An example code in MATLAB is given below:[3]

img1 = imread('pout.tif');

minimum_pixel = double(min(min(img1))); % give minimum pixel intensity
maximum_pixel = double(max(max(img1))); % give maximum pixel intensity
img2 = uint8(255*(double(img1) - minimum_pixel)/(maximum_pixel-minimum_pixel));

figure ;
title('Contrast adjustment by linear scaling')
imshow([img1,img2])

How to obtain the function for contrast stretching? edit

Suppose we are asked to obtain the gray level transformation function that stretches gray scale range [0, 50] into [0, 100], stretches the range [50, 80] into [100, 150] shifts range [80, 130] to [150, 200] and compresses the range [130, 250] into [200, 250].

Let the resulting function be S =   where

r is the pixel value, a = 50, b = 80, c = 130, L-1 = 250 , S1 = 100, S2 = 150, S3 = 200.

Obtaining the constants using the formula for calculating slope,

 

 

 

 

now substituting all the constants we get the gray level transformation function as:

S =  

We can now apply this function on every pixel value in the image to get the transformed image.

Applying the Transformation Function on an Image edit

Suppose we are given an input image F=   and its gray-level transformation function is given as S =  .

Now, we apply this function to the input image and get the output image A.

Case 1: when  

We can see that for F(0,0) r=7,

so A(0,0) = 0.5r = 0.5 x 7 = 3.5

Similarly applying for all values of r that satisfy the condition, we get

F =  


Case 2: when  

Applying for all values of r that satisfy the condition, we get

F =  


Case 3: when  

Applying for all values of r that satisfy the condition, we get

F =  

This is the final output image after applying the gray level transformation function.

Reference section edit

  1. ^ a b "Point Operations - Contrast Stretching". homepages.inf.ed.ac.uk. Retrieved 2024-04-24.
  2. ^ S., Jayaraman; et al. (Veerakumar, T, Esakkirajan, S) (2009). Digital Image Processing. Tata McGraw Hill Education Pvt Ltd. ISBN 9780070144798.
  3. ^ "Linear contrast stretch to image?". in.mathworks.com. Retrieved 2024-04-28.



Return to the tutorial