Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Experiment 6A 10-236

Title: To implement Contrast Stretching

Estimated time to complete this experiment: 2 hours

Objective: In this experiment, student should be able to understand the formula to perform contrast
stretching of a black and white image.

PEO to be achieved:

Expected Outcome of Experiment:


Obtaining higher contrast image from an existing image

Books/ Journals/ Websites referred:


 http://www.mathworks.in/help/matlab/

Pre Lab/ Prior Concepts: Basic MATLAB knowledge of the standard formula to obtain Digital
Negative
______________________________________________________________________________________

Historical Profile:
1816 – Nicéphore Niépce succeeds in making negative photographs of camera images on paper coated
with silver chloride, but cannot adequately "fix" them to stop them from darkening all over when exposed to
light for viewing

New Concepts to be learned: How to increase or decrease the pixel values in an image.

Software & Hardware Required: MATLAB software and PC Hardware


Experiment 6A 10-236

Flow Chart:

Start

Read the image in an object


Accept r1,r2,s1 and s2

Use given formulae to adjust every pixel


value in the image

Plot the image

Stop

Stepwise Procedure:
1. Open Matlab software
2. Goto New  Script
3. Write the program code given below.
4. Save the code with an “.m” extension.
5. Run the code to get the output.

Program Code:

clc;
clear all;
r=imread('cameraman.tif');
[x y]=size(r);

r1=input('Enter the value of r1 : ');


r2=input('Enter the value of r2 : ');
s1=input('Enter the value of s1 : ');
s2=input('Enter the value of s2 : ');

l=s1/r1;
Experiment 6A 10-236
m=(s2-s1)/(r2-r1);
n=(255-s2)/(255-r2);
for i=1:x
for j=1:y
if(r(i,j)<r1)
rcs(i,j)=l*r(i,j);
else if(r(i,j)<r2 && r(i,j)>=r1)
rcs(i,j)=m*(r(i,j)-r1)+s1;
else
rcs(i,j)=n*(r(i,j)-r2)+s2;
end
end
end
end

subplot(1,2,1);
imshow(r);

subplot(1,2,2);
imshow(rcs);

Output:

Enter the value of r1 : 100


Enter the value of r2 : 200
Enter the value of s1 : 150
Enter the value of s2 : 250

Conclusion: Therefore we obtained a contrast stretched image of the original image.


Experiment 6A 10-236

Real Life Application:


Converting images into a higher quality formats.

_________________________________________________________________________
_______

Viva Questions:

1. Define Contrast.
 Contrast is the difference in luminance and/or color that makes an object (or its
representation in an image or display) distinguishable. In visual perception of the real world,
contrast is determined by the difference in the color and brightness of the object and other
objects within the same field of view.

2. What is contrast stretching?


 In image processing, normalization is a process that changes the range of pixel intensity values.

3. What is the transformation formula for contrast stretching?


 s = l*r 0 <= r < r1
s = m(r-r1)+s1 r1<= r < r2
s = n(r-r2)+s2 r2<= r <=255

_________________________________________________________________________
_______

You might also like