Friday Lab 2
Friday Lab 2
Lab Assignment 2
Continue your Image processing lab work in google colab using OpenCV computer vision
library. In this lab you will study various issues related to contrast stretching of gray values in
an image.
A number of image transformations have been suggested in the assignment. You are required
to plot each transformation, show the original and transformed images side by side, and
provide explanation for the change in image, or justify it.
Submit a PDF file for this assignment.
1. Download the following images or borrow similar images with poor contrast from the net
i) Pick up one of the above images and carry out single leg contrast stretching with
following parameters: R1 =0, S1 = 30, R2 = 225, S2 = 255
Plot the contrast stretch line, taking hint from following code
import matplotlib.pyplot as plt
import numpy as np
# define data values
x = np.array([0, 30, 180, 255]) # X-axis points
y = np.array([0, 0, 255, 255]) # Y-axis points
School of Computer Science Engineering and Technology
plt.plot(x, y) # Plot the chart
plt.show() # display
Show the original image and the transformed image. Discuss whether this transformation brightens
the picture, darkens the picture, improves contrast, converts into binary or whatever the output.
Justify the output in relation to your plot.
Repeat the above steps with other sets of parameters given below:
Plot the line, carry out transformation, show the output, and provide explanation for it.
ii) R1 = 30, S1 = 0, R2 = 255, S2 = 225
v) R1 = 0, S1 = 255, R2 = 255, S2 = 0
2. This part deals with transforming very dark pictures. Carry out two-leg contrast stretching
on the following images with following parameters, plot the curves, and justify the nature
of the output in each case
a. R1 = 0, S1 = 0, R2 = 125, S2 =200, R3 = 255, S3 =255
b. R1 = 0, S1 = 0, R2 = 80, S2 =200, R3 = 255, S3 =255
3. This part is also for very dark images. Carry out Log transformation on images used in the
last problem. Repeat the same steps as before.
School of Computer Science Engineering and Technology
s = c * log (1 + r)
4. This part relates to handling very bright images. Carry out two-leg contrast stretching on
following images with following parameters, justify the nature of the output in each
case. Plot the curves, and provide explanation for the outputs as before. Try with other
bright image from the net.