Description
The sample image “SanFrancisco.jpg” is to be used for all three questions.
Contrast Stretching
Contrast in an image is a measure of the range of intensity values within an image, and is
the difference between the maximum and minimum pixel values. The full contrast of an 8-
bit image is 255(max)-0(min)=255, and anything less than that results in a lower contrast
image.
Contrast stretching attempts to improve the contrast of an image by stretching
(linear scaling) the range of intensity values. Assume that Or is the original image and Tr is
the transformed image. Let a and b be the min and max pixel values allowed in an image (8-
bit image, a=0 and b=255), and let c and d be the min and max pixel values in a given image,
then the contrast stretched image is given by the function:
𝑻𝒓 = (𝑶𝒓 − 𝒄) (
𝒃 − 𝒂
𝒅 − 𝒄
) + 𝒂
QUESTION 1: Read the given grey scale image and perform contrast stretching to improve
the quality of the image.
Histogram
The histogram of an image shows the frequency of pixel intensity values. It gives statistical
information and removes the location information of the pixels. For a digital image with
grey levels from 0 to L-1, the histogram is a discrete function 𝒉(𝑶𝒓𝒌
) = 𝒏𝒌, where Ork is the
k
th grey level and nk is the number of pixels with a grey level rk.
Figure 1: Histogram (Picture from [3]).
QUESTION 2: Write a function that computes the histogram of the given grey scale image
and displays a plot.
Image Edges
Edges are an important source of semantic information in images, and they occur in human
visual perception at divisions between different areas of brightness, colour and texture. A
grey scale image can be thought of as a 2D representation of heights and areas of different
brightness live at different heights. A transition between different areas of brightness in an
image I , means there must be a steep slope which we formalise as the gradient of
∇I = (
∂I
∂x
,
𝜕𝐼
𝜕𝑦 )
of the Image.
Now our image I is discrete so we approximate the continuous quantities ∂I
∂x
and 𝜕𝐼
𝜕𝑦 by finite difference kernels. A simple example of a finite difference kernel is the
Sobel filter (F_x and F_y), which is the subject of the following question.
QUESTION 3 (1 mark): With the given image, use the Sobel operator to compute the image
gradients at x and y directions. To do this, first define the 2D filters (F_x and F_y). Then
perform convolution between the image and F_x to obtain the gradients at x direction, and
similarly perform convolution between the image and F_y to obtain the gradients at y
direction.
Submit the two gradient outputs as images for marking.
F_x = [
−1 0 1
−2 0 2
−1 0 1
]
F_y = [
−1 −2 −1
0 0 0
1 2 1
]
Note: The OpenCV built-in sobel functions can be applied to achieve the result. This can be a
way of verifying the gradient outputs. (Hint: use cv2.CV_8U as the data type)
REFERENCES
[1].Krig S. (2014) Image Pre-Processing. In: Computer Vision Metrics. Apress, Berkeley,
CA, https://link.springer.com/chapter/10.1007/978-1-4302-5930-5_2#citeas
[2].http://cursa.ihmc.us/rid=1GJRS5FYJ-HBJGJG1FF0/Cindy%20and%20Melonie’s%20CMAP%20Digital%20Imaging%20Processing.cm
ap.cmap
[3].http://machinelearninguru.com/computer_vision/basics/convolution/image_convol
ution_1.html