Digital Image Processing Lab Manual# 5
Digital Image Processing Lab Manual# 5
Objective:
The objective of this lab is to implement thresholding on images to convert them to binary,
perform different transformation operations on images, find out the histogram of an image
and perform histogram equalization.
Theory:
Histogram Calculation
Here, we use cv2.calcHist()(in-built function in OpenCV) to find the histogram.
cv2.calcHist(images, channels, mask, histSize, ranges[, hist[, accumulate]])
images : it is the source image of type uint8 or float32 represented as “[img]”.
channels : it is the index of channel for which we calculate histogram. For grayscale
image, its value is [0] and
color image, you can pass [0], [1] or [2] to calculate histogram of blue, green or red channel
respectively.
mask : mask image. To find histogram of full image, it is given as “None”.
histSize : this represents our BIN count. For full scale, we pass [256].
ranges : this is our RANGE. Normally, it is [0,256].
Page 1 of 4
Contrast stretching is a simple 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. Normally (min, max) (0, 255)
p=
((p-min)/(max-min)) *255
Instead of blindly computing the dynamic range using just the minimum and maximum pixel
values, a more robust and adaptive technique is to use the 5th and 95th percentiles of the
input values when deriving the dynamic range of the input image.
Page 2 of 4
Thresholding is the operation through which an image can be converted into a binary
image/black & white i.e. having only two distinct levels. threshold value can be the mean or
median etc. of the image.
Gray level Slicing is used to highlight a specific range of gray levels in an image
Transformation operations help enhance the quality of the image by applying operations
like log, inverse log and power on the entire image. Different type of transformation yields
different results.
Power law transformation: The general form of Power law (Gamma) transformation
function is
s = c*rγ
Where, ‘s’ and ‘r’ are the output and input pixel values, respectively and ‘c’ and γ are the
positive constants.
Page 3 of 4
NAME: ROLL:
Lab Tasks:
(a) (b
)
Lab Task 1:
Apply contrast stretching on image (a) by setting min and max of the input values to 0 and
255 respectively.Apply contrast stretching on image (b) by setting 5th and 95th percentiles of
the input values to 0 and 255 respectively. Also convert into binay using mean as threshold.
Lab Task 2:
After obtaining constrast streatched images from lab task 1 .Apply Power Law transformation
for the following values of γ (0.2, 0.5, 1.2 and 1.8) . Make sure to adjust data types
accordingly.
Lab Task 3:
After obtaining constrast streatched images from lab task 1 .Apply Gray level slicing using
lower limit 100 and upper limit 200. Set all these values to 210.
Page 4 of 4