Sale!

# COMP9517 Lab 1 solved

Original price was: \$35.00.Current price is: \$30.00.

Category:

5/5 - (1 vote)

## 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,