DIP Lab-6
DIP Lab-6
Name: _________________________________
Enrollment #: _________________________________
Class: _________________________________
Objective
In today’s lab you will explore intensity transformations and histogram plotting of an image. By
the end of this lab, you should be able to apply linear, log and power law transformations to
an image and find intensity histogram of an image.
Tasks
Intensity Transformations
Intensity transformation T is a function which, when applied to an intensity ‘r’ gives a
processed or transformed intensity ‘s’ at that specific pixel.
Inverse Transformation
where, r is the current intensity at a pixel point (x, y) and s is the resultant intensity after the
transformation function is applied onto r. L is the max. gray level value, usually L = 28 – 1 = 256
–1 = 255.
Python Function to implement inverse transformation:
im.point(lambda x: 255 - x) using PIL
Logarithmic Transformation:
Logarithmic transformations are implemented as follows:
where, r is the current intensity at a pixel point (x, y) and s is the resultant intensity after
the transformation function c * log(1 + r) is applied onto r. Example:
Exercise 1
image, you can pass [0],[1] or [2] to calculate histogram of blue,green or red
channel respectively.
3. mask : mask image. To find histogram of full image, it is given as “None”. But if you want
to find histogram of particular region of image, you have to create a mask image for that
and give it as mask. (I will show an example later.)
4. histSize : this represents our BIN count. Need to be given in square brackets. For full
scale, we pass [256].
5. ranges : this is our RANGE. Normally, it is [0,256].
import cv2
def plot_image(imag, title=''):
pylab.title(title, size=20), pylab.imshow(imag)
pylab.axis('off') # comment this line if you want axis ticks
im = cv2.imread("/content/sample_data/images/parrot.JPG")
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
pylab.style.use('ggplot')
pylab.figure(figsize=(15,5))
pylab.subplot(121), plot_image(gray, 'original image')
pylab.subplot(122), plot_hist(gray,'histogram for RGB channels')
pylab.show()
Exercise 2
Exercise 3
Write a function which loads the image ‘cameraman.jpg’. Apply the power law
transformation to this image using gamma = 2 and gamma = 0.5. Compare and
analyze the histograms of the original and the processed images. The program
output should be similar to the one indicated in Figure 1.