Assignment2 40168195
Assignment2 40168195
Assignment 2
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.
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.
Output:
Figure 1 Output of written Method
figure
imshow(newimage);
imwrite(newimage, "img.png");
Output:
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.