Dip Lab-5
Dip Lab-5
Name: _________________________________
Enrollment #: _________________________________
Class: _________________________________
Objective
The purpose of today’s lab is to have an insight into the gray intensity slicing,
histogram equalization and contrast stretching.
Submission Requirements
You are expected to complete the assigned tasks within the lab session and show them to
the lab engineer/instructor. Get the lab journal signed by your instructor and submit it by the
end of lab session.
Gray-Level Slicing
Exercise 1
Consider a function f(x) defined over an image ‘cameraman.tif’ with the intensities in
the range [0 1], as defined below:
Exercise 2
Write a MATLAB program for the following function on an input image ‘cameraman.png’.
Also show your result.
Hints:
1. Convert the given graph into a Mathematical function.
2. Find equation of line for x>0.5.
This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00
https://www.coursehero.com/file/98215667/Journal-06pdf/
Histogram Equalization
Histogram equalization is the process of re-allocating intensity values of the pixels in an image such that
the output image contains uniform distribution of intensities defined by a monotonically increasing
function T(r).
Function in Python:
cv2.equalizeHist(gray): equalizes histogram of an input image in_img for the specified gray
levels L.
This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00
https://www.coursehero.com/file/98215667/Journal-06pdf/
Exercise 3
Write a function named ‘myhist_equ’ to MANUALLY equalize histogram of an
image ‘cameraman.png’ and map corresponding results:
INPUTS: image
OUTPUTS: Display the input image as well as equalized (resultant) image along
with histogram before and after histogram equalization.
Contrast Stretching
Contrast stretching attempts to improve an image by stretching the range of intensity values it contains
to make full use of possible values. Unlike histogram equalization, contrast stretching is restricted to a
linear mapping of input to output values. The result is less dramatic, but tends to avoid the sometimes
artificial appearance of equalized images.
For each pixel, the original value r is mapped to output value s using the function:
Where rmin and rmax represent the minimum and the maximum gray values in the image, L-1
represents the maximum gray level in the image (for 8 bit images, L-1 = 255).
From the view point of implementation, convert the image to double, hence the factor L-1 = 1.
This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00
https://www.coursehero.com/file/98215667/Journal-06pdf/
Exercise 4
INPUTS: image
OUTPUTS: Display the input image as well as the contrast stretched (resultant) image
along with the histogram of each. Load the image ‘person.png’ and display the output
as illustrated in Figure 3.
This study source was downloaded by 100000853928643 from CourseHero.com on 10-03-2022 08:00:20 GMT -05:00