$24
• Thresholding (12 Points)
Thresholding is the simplest method of image segmentation. From a grayscale image, thresholding can be used to create binary images. Here, each pixel in an image is replaced with a foreground label (i.e. a white pixel with 255 value) if the image intensity Ii;j satis es some pre-de ned condition (Ex. if Ii;j > T) in relation to threshold values (Ex. T, T1, T2), or with a background label (i.e. a black pixel with 0 value) otherwise.
Simple Binary Thresholding:
Si;j =
255
if Ii;j > T;
(1)
0
otherwise.
(2)
Window Binary Thresholding:
255
if T1 < Ii;j < T2;
(3)
Si;j = 0
otherwise.
(4)
You are given an image named "numbers.jpg" (Figure 1(a)) which contains multiple di erent multi-digit numbers. Your task is to threshold the image using the pre-de ned conditions for thresholding de ned above.
Note that you are not allowed to use the openCV cv2.threshold function for this task. Instead implement thresholding using basic python or numpy functions.
(a) (b)
Figure 1: (a) Input image for thresholding, (b) Example of output image of thresholding. Note that only numbers "007", "11", and "99" are segmented (foreground pixels).
2
1. Threshold the image at three di erent thresholds 1) 45 2) 90 and 3) 160 using simple binary thresholding as de ned above. Display thresholded images at these thresholds. (3 points)
2. Write your observations about thresholded images at di erent thresholds. How many and which numbers are segmented at each threshold? Note: A number is considered as segmented if all digits of that number are clearly visible as foreground or background in the thresholded image. What else do you observe at each threshold? (3 points)
3. Threshold the image using Window binary thresholding using three di er-ent ranges of thresholds. 1) T1=55 and T2=110, 2) T1=110 and T2=160, 3) T1=55 and T2=160. Write your observations. Display images at these di erent thresholds. How many and which numbers are segmented at each threshold? (3 points)
4. In a practical application, we vary the value of the hyper-parameters (here, the threshold values) for any of the above-mentioned thresholding meth-ods, such that we get the desired output. Find a threshold value such that only numbers "007", "11", and "99" are segmented (i.e. considered as foreground - white pixel - 255 value). See Figure 1(b). Report your nding and display corresponding thresholded images for at least three di erent threshold values, and write how it helped you in narrowing down the desired hyper-parameter value. Note that the emphasis in to not get the exact output but to explore di erent hyper-parameters and report your nding. (3 points)
• Denoising (18 Points)
You are not allowed to use OpenCV/Scikit-image functions for this section unless speci ed otherwise. For this question, you are expected to write your own code in NumPy for convolution. (4 points)
Refer to lecture slides on Image ltering covered during class. For handling boundary conditions, you are expected to use zero padding (covered during lec-ture/tutorial).
You are given a clean image named ’Tower’ (Figure 2(a)) and an image cor-rupted by additive white Gaussian noise (Figure 2(b)).
Apply the following ltering operations:
1. Filter the noisy image using a 3 3 Gaussian lter with variance equal to 2. Display ltered image along with original image. (2 points)
2. Filter the noisy image using a box lter of the same size. Display ltered image along with original image. (2 points)
3
(a) (b) (c)
Figure 2: Input images for denoising. (a) clean image [1] (b) image corrupted with Gaussian noise (c) image corrupted with salt and pepper noise.
3. Compare the Peak-Signal-to-Noise-Ratio (PSNR) of both of the denoised images to that of the clean image and state which method gives the supe-rior result. Use the PSNR function provided by opencv/scikit-image. (3 points)
You are also given an image corrupted by salt and pepper noise (Figure 2(c)).
Apply the following ltering operations:
4. Filter the noisy image using the same Gaussian lter as used in the previ-ous question. Display ltered image along with original image. (2 points)
5. Filter the noisy image using a median lter of the same size. Display ltered image along with original image. (2 points)
6. Compare the PSNR of both of the denoised images to that of the clean im-age and state which method gives a better result. Use the PSNR function provided by opencv/scikit-image. (3 points)
• Sobel edge detector (16 Points)
In this question, you will assess the e ect of varying the kernel size on the results of an edge detection algorithm. You will detect edges in a clean image named, ‘circles’ (Figure 3(a)). You are allowed to use OpenCV/Scikit-image functions for this section, including the convolution function.
• Apply a Sobel edge detector with the kernel size of 3 3, 5 5 and 7 7 to the image. Threshold the ltered image to detect edges. Use two values of thresholds: 10% and 20% of the maximum pixel value (magnitude) of
4
(a) (b)
Figure 3: "Circles" [2]: Input image for edge detection. (a) clean image (b)
image corrupted with Gaussian noise.
the ltered image. Display phase, magnitude, and thresholded images for di erent kernel sizes and di erent thresholds. (6 points)
• Comment on the e ect of lter size on the output. (2 points)
Next, you will evaluate the e ect of denoising prior to edge detection. For the following questions, you will use noisy image as shown in Figure 3(b).
• Apply a Sobel edge detector with the kernel size of 3 3. Threshold the ltered image to detect edges. Use two values of thresholds: 10% and 20% of the maximum pixel value in magnitude of the ltered image. Display phase, magnitude, and thresholded images for di erent thresholds. (3 points)
• Denoise the image with a 3 3 box lter and then apply the same Sobel edge detector, with the same values of the thresholds, from the previous question. Display original and ltered image side by side. Display phase, magnitude, and thresholded images for di erent thresholds. (3 points)
• Comment on the e ectiveness of using denoising prior to edge detection. (2 points)
5