0% found this document useful (0 votes)
50 views10 pages

Assignment4 40168195

This document contains an assignment submitted by Virag Vora (40168195) for their Image Processing course (COMP 6771) at Concordia University in the Fall 2022 semester. The assignment contains theoretical questions about Otsu's thresholding method, the Hough transform, and circle detection, as well as programming questions involving applying Otsu's method and smoothing an image, performing wavelet transforms using Haar and Daubechies-4 wavelets on the Lena image up to level 3. Code and output images are included.

Uploaded by

saumya11599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views10 pages

Assignment4 40168195

This document contains an assignment submitted by Virag Vora (40168195) for their Image Processing course (COMP 6771) at Concordia University in the Fall 2022 semester. The assignment contains theoretical questions about Otsu's thresholding method, the Hough transform, and circle detection, as well as programming questions involving applying Otsu's method and smoothing an image, performing wavelet transforms using Haar and Daubechies-4 wavelets on the Lena image up to level 3. Code and output images are included.

Uploaded by

saumya11599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CONCORDIA UNIVERSITY

COMP 6771 – Image Processing


FALL 2022

Assignment 4

Submitted By: Virag Vora (40168195)


Part I: Theoretical Questions
Question 1: (8 points) In Otsu’s method for thresholding in Chapter 10 of the textbook (Page
749). We have the following equations:

You must give details of your derivations.


Question 2: Explain why Hough transform for lines cannot be carried out in the Cartesian (x, y)
coordinate system. Give details on how Hough transform for line searching is done on a set of n
points.
• First, the Hough transform is only applied on the images where the edge detection is already
performed on the image and we have a binary image containing all the edges in the form of
lines or other shapes.
• In the cartesian coordinate system, it uses x and y which represent the points in the coordinate
system and which when combined produce a line whose equation is given by: y = ax + b.
While, in Hough Space, the horizontal axis represents the slope ‘a,’ and the vertical axis
represents the arbitrary constant or the intercept of the line at any given point in that space. So,
any point in the Hough Transform space represents the line present in the edge detected image
(Example: b = axi + yi).
• But, as we know, the vertical line has a slope of a = infinite in the above equation so it will be
impossible to generate all possible lines with a slope of a = infinite. Thus, it is represented as
a straight line passing through the origin and perpendicular to that straight line with the
equation ρ = x cos(θ) + y sin(θ) where ρ is the length of the line and θ is the angle between x
axis and that line.
• As we have now converted the constants a and b into the form of ρ and θ, the Hough space is
now in the form of ρ and θ. This will generate the same results with a small difference that
instead of a point representing the straight line will be a cosine curve. This is helpful as it can
now represent any angle and any intercept that covers all the possible slopes of a line including
an infinite slope.
• Now we map all the points into cosine curves and the Hough space will consist of various
intersecting cosine curves which represent the same line for different points in the edge image.
We must set a threshold for these points. If the intersecting cosine lines are more than the
threshold, we can say that the line is detected.
• The equation is: ρ = x cos(θ) + y sin(θ)
• The range of values of θ is from [0, 180] degrees. And the value of ρ is from [-d, d]. Here d
represents the length of the edge’s diagonal.
Question 3: Here is a binary image of polka dots of two different sizes. Assume that the sizes
of the dots are known, can you devise an algorithm using the knowledge you have learnt to obtain
the number of the bigger dots automatically?

• The first step to do on that Polka-dot binary image is to detect the edges in that image.
• Now, as the edges are detected, the solid circles will be converted to the circular rings in the
edge image. Thereafter, we can perform the Circle Hough Transform on that image.
• In the image given above, there are circles with 2 different radii. The smaller one and the bigger
one with the radius known to us.
• Here, we have an unknown number of circles present in the image so we will have to start with
finding one circle in order to obtain the threshold value which will represent the centroid of a
all the circles that will be reflected in the Hough Space to identify one circle, i.e., all the points
of that one circle in the original image of radius r in the Hough space where all those circles
will intersect at a single point (a, b) in that space which represents the center of the original
circle.
• When we find the number of intersecting points in the Hough space at that point, it will be
considered as the highest Hough Score of that image. Using this score, we can set the threshold
of the image.
• If the found circle is correct, we will gradually reduce that threshold until the centers of circles
in that image are as per the geometry in the original image. We must do this because there can
be multiple intersections of the circles which might not be the center of circles in the original
image but it is still present in the Hough space.
• We must specify the maximum number of circles we want to find in the image as there can be
many intersecting points in the Hough Space which might or might not determine the center
of the circle in the original image as explained above.
• Thus, if there are let us say 10 circles in the original image, and we specify that the max number
of circles we want to find is 5, then it will select the first 5 circles with the highest Hough score
in the Hough space considering the threshold value set. Similarly, if there are 10 circles in the
image and we specify the max number of circles as 15, it will surely count the real 10 circles
present in the image but it will also try to consider the points which do not really represent the
circle in the original image but still as they have intersecting points in the space.
• So, in this case, the option of setting a perfect threshold value to avoid fake centers can be a
good practice. This can be achieved earlier by detecting only one image and setting the
threshold value as high as possible to avoid the fake intersection of Hough circles.
• In this way, we can set the max number of circles to find as infinite, and thus we can get the
number of circles present in the image as an exact number considering the radius of the circle,
the threshold of the points intersecting in Hough Space, and the area in the image where we
can detect a circle.
Part II: Programming Questions
Question 1: Download the image (tools_noisy.png) from the course webpage. This image
contains noise.

a) Apply Otsu’s algorithm to the image and show the result.

image = imread(“tools_noisy.png”);
gray = graythresh(image);
binary = imbinarize(image, gray);
imshow(binary);

Figure 1 Original Image(Left), Otsu's Algorithm on the image(Right)

b) Smooth the image by a 5 by 5 averaging filter, then apply Otsu’s algorithm and show the
result. Compare the results in a) and b).

image = imread(“tools_noisy.png”);
filter = fspecial(“average”, 5);
blur_image = imfilter(image, filter);
gray = graythresh(blur_image);
binary = imbinarize(blur_image, gray);
imshow(binary);
imshow(blur_image);

Figure 2 5x5 Average Filtered Image


Figure 3 Otsu's Algorithm on Blurred Image

Comparison:
• If we do not apply blurring in the image and if we do the Otsu’s algorithm, the image obtained
in the Figure 1 will be full of noise as it will consider the noise dots also for making the image
binary.
• Thus, before applying the Otsu’s Algorithm on the original image, the image was first blurred
out which removed the noise from the image and due to that, the binary image obtained by the
Otsu’s Algorithm was noise free and clear partitions of the objects in the image was observed.
• However, at some points we can observe that the algorithm is not able to clearly identify the
difference between the objects and the background thus in this area the partition is not perfect.
Question 2: Download the image lena.tif from the course webpage, then do the following with
the MATLAB function, wavedec2():
a) Perform wavelet transform of the Lena image up to and including level 3 by using Haar
wavelet, and show your results.
image=imread("lena.tif");

[C, S] = wavedec2(image, 3, "haar");


[H, V, D] = detcoef2('all', C, S, 3);
A = appcoef2(C, S, 'haar',3);

vImage = wcodemat(V, 255, 'mat', 3);


hImage = wcodemat(H, 255, 'mat', 3);
dImage = wcodemat(D, 255, 'mat', 3);
approx = wcodemat(A, 255, 'mat', 3);

subplot(2,2,1)
imshow(uint8(approx))
title('HAAR WAVELET Level 3 Approximation')
subplot(2,2,2)
imshow(uint8(hImage))
title('HAAR WAVELET Level 3 Horizontal Coefficient')
subplot(2,2,3)
imshow(uint8(vImage))
title('HAAR WAVELET Level 3 Vertical Coefficient')
subplot(2,2,4)
imshow(uint8(dImage))
title('HAAR WAVELET Level 3 Diagonal Coefficient')

Figure 4 Output of Haar Wavelet Transform Level 3


b) Perform wavelet transform of the Lena image up to and including level 3 by using Daubechies-
4 wavelet (check out the ‘wname’ flag for available wavelets), and show your results.
image=imread("lena.tif");

[C, S] = wavedec2(image, 3, "db4");


[H, V, D] = detcoef2('all', C, S, 3);
A = appcoef2(C, S, "db4",3);

vImage = wcodemat(V, 255, 'mat', 3);


hImage = wcodemat(H, 255, 'mat', 3);
dImage = wcodemat(D, 255, 'mat', 3);
approx = wcodemat(A, 255, 'mat', 3);

subplot(2,2,1)
imshow(uint8(approx))
title('DAUBECHIES-4 WAVELET Level 3 Approximation')
subplot(2,2,2)
imshow(uint8(hImage))
title('DAUBECHIES-4 WAVELET Level 3 Horizontal Coefficient')
subplot(2,2,3)
imshow(uint8(vImage))
title('DAUBECHIES-4 WAVELET Level 3 Vertical Coefficient')
subplot(2,2,4)
imshow(uint8(dImage))
title('DAUBECHIES-4 WAVELET Level 3 Diagonal Coefficient')

Figure 5 Output of Daubechies Wavelet Transform Level 3

c) Visually compare the quality of the approximation images at level 3 of the two cases and give
your comments.
Figure 6 Comparison between Haar Wavelet and Daubechies-4 Wavelet

As we can see that the Daubechies-4 wavelet is able to detect edges more accurately compared to
Haar wavelet. As the window size of Daubechies-4 wavelet transform is smaller, the edges are
more efficiently detected and thus, it is also able to detect major frequency change in the image
compared to Haar wavelet.

You might also like