50% found this document useful (2 votes)
126 views10 pages

Assignment2 40168195

This document contains an assignment submitted by Virag Vora for COMP 6771 - Image Processing at Concordia University in Fall 2022. The assignment contains 3 theoretical questions and 1 practical question regarding image processing techniques. For the practical question, the student implemented an adaptive thresholding algorithm on an image and compared the results to MATLAB's inbuilt adaptthresh() function.

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
50% found this document useful (2 votes)
126 views10 pages

Assignment2 40168195

This document contains an assignment submitted by Virag Vora for COMP 6771 - Image Processing at Concordia University in Fall 2022. The assignment contains 3 theoretical questions and 1 practical question regarding image processing techniques. For the practical question, the student implemented an adaptive thresholding algorithm on an image and compared the results to MATLAB's inbuilt adaptthresh() function.

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 2

Submitted By: Virag Vora (40168195)


Part I: Theoretical Questions

Question 1:
In character recognition, text pages are reduced to binary form then followed by a thinning process
that will reduce the characters to strings of binary 1s on a background of 0s. Due to noise the
binarization and thinning processes could result in broken strings of 1s with gaps ranging from 1
to 5 pixels. The aim is to repair it so that there are no gaps in the strings of 1s. This is done as
follows:
Blur the binary image by an averaging filter then apply a thresholding method to convert it back
to binary form. For this approach, please give the minimum size of the blurring mask and the
minimum value of the threshold to accomplish the task.

Answer: As there are a maximum of 5 gaps encountered, in the worst case, there will be 5
adjacent gaps available. So, in order to get the smallest filter of odd length to avoid this gap of 5,
we will have to use a filter of 7*7 size. Thus, if we use the filter of 7*7, we will get at least 2 pixels
with non-zero values. Additionally, apart from avoiding this gap, we will also get the convolution
value of non-zero. Which will avoid 0 as the output of element wise multiplication of filter to the
image.
If we want to select the threshold value for this filter, we will use the lowest value obtained
after applying the 7*7 filter to the whole image. As we are guaranteed that the lowest point will
never be zero (because using 7 size filter will cover at least 2 non-zero-pixel values which will
give an average >0), we can select the lowest average value obtained as our threshold. This will
result in the perfect value for blurring mask.
Question 2:
In class, we have seen Laplacian filters, such as the following

Write down a 5-by-5 Laplacian-like filter with the center element equal to -16. What general rules
should you follow to build such a filter? If we apply this filter to an image, do we get a sharper
image compared to those images obtained with filter A, B, and C? Explain your answer.

Answer: For using a filter on the image, for any given pixel at position (x, y), we do
element wise multiplication of filter with all the positions of the image (w or w/o padding).
● In Laplace-like filter, the filters are built in such a way, that the weightage is given to the
center pixel of the filter. Thus, the filter should contain the middle (absolute) value
comparatively higher than the neighbor values of filter.
● Additionally, if the center value of the Laplace filter is negative, the other values of the
filter should be positive and vice versa. This would help us to prove the other property of
the Laplace filter.
● Using the second order partial derivative formula to generate Laplace filters, it is necessary
that the summation of all the values of the filter will result in 0.
In a normal sharpening filter, there are two possibilities. To sharp the image, there can be diagonal
edge detection and the vertical/horizontal edge detection.

Thus, one of the Laplacian-like filters with the center element equal to -16 is as below:
0 0 1 0 0

0 1 2 1 0

1 2 -16 2 1

0 1 2 1 0

0 0 1 0 0

In the above 5*5 filter, it follows all the Laplace filters rules. Also, the center element is given
more weightage compared to the neighbor elements and the summation of all the elements is equal
to 0.

As compared to the filters A, B and C given in the question, the 5*5 filter will not give as good
results because the size of the above filter is big so it will be more generalized the reason behind
this is that it will consider a wider range of pixel values to generate the pixel at the center.

Sharpness comparison for all the filters:


(Most Sharpening Filter) C > A > B > 5*5-filter (Least Sharpening Filter)

As the filter in C has greater value in the center and uses all the neighbor values, the sharpness will
be the highest. And for A and B filters, the diagonal filter(A) is able to obtain more sharpness
compared to filter B.
Question 3: Fourier Transform Questions:
a) Study Example 4.1 in the textbook, then follow the steps in that example to find the Fourier
Transform of the function f(t) = A for 0 ≤ t ≤ W and f(t) = 0 otherwise; where both A and W are
constants. Explain the differences between your result and the result in Example 4.1. Consider the
case where A = W = 1, what is the Fourier Transform of f(t) in this case?
b) Use the result of Example 4.1 to find the Fourier Transform of the tent function. The tent
function is shown below on the left. Note that the tent function is the convolution of two box
functions shown in Fig. 4.4(a) (Right Image).
Part II: Practical Questions

Question 1: Download the image from the assignment folder then carry out the adaptive
thresholding algorithm to binarize the text in the image without the shadow. Please show your
results, discuss about your choice of parameters and filters, and compare your results with the
adaptthresh() function in MATLAB.

Adaptive Thresholding Algorithm:


RGB = imread("Doc.tiff");
gray = rgb2gray(RGB);
F = 5;
C = 5;
paddedgray = padarray(gray,[((F - 1) / 2) ((F - 1) / 2)], 0, 'both');
threshold = zeros(size(gray));
newimage = zeros(size(gray));
for r = 1:size(gray, 1)
for c = 1:size(gray, 2)
tempVal = int16( 0 );
for x = r:r + F - 1
for y = c:c + F - 1
tempVal = tempVal + int16(paddedgray(x, y));
end
end
threshold(r, c) = (tempVal ./ (F * F)) - C;

if (threshold(r, c) > gray(r, c))


newimage(r, c) = 0;
else
newimage(r, c) = 255;
end
end
end
figure
imshow(newimage);

Output:
Figure 1 Output of written Method

Using Inbuilt method adaptthresh() of Matlab:


RGB = imread("Doc.tiff");
gray = rgb2gray(RGB);
val = adaptthresh(img,0.5, 'ForegroundPolarity', 'dark');
newimage = imbinarize(gray, val);

figure
imshow(newimage);
imwrite(newimage, "img.png");

Output:

Figure 2 Output using inbuilt adaptthresh() method


I have chosen 5*5 filter size as averaging filter and used 5 as the arbitrary constant ‘c’ in order to
achieve good adaptive thresholding of the given image.
● The reason behind using 5 as c is that if I decrease the value of c to 1 or 2, the noise value
increases. If the value of c increases, it fades out the image and the characters present in
the images are diluted and converted to white area as it considers the detailed information
of the image as Noise. Thus, according to me, 5 is a suitable value of c in this case.
● If we use the filter size as a smaller value, it goes in very detailed sharpening of the image.
But, considering 5 * 5 for the filter size gave almost the result compared to 3 * 3. Also, if
the value of Filter size is increased, more generalized form of sharpening is done. So, it is
better to have filter size as small as possible though it will increase computation.

Comparison between Inbuilt method and Function made by me: The image obtained by using
the inbuilt method is a little darker and thicker handwriting as compared to the image obtained by
my function. This image might be achieved by my function if we decrease the value of c by a small
value, and increase the filter size by a little.

You might also like