Starting from:
$30

$24

Image Filtering


Please submit your assignment solutions electronically via the myCourses assignment dropbox. The submission should include a single jupyter notebook. More details on the format of the submission can be found below. Submissions that do not follow the format will be penalized 10%. Attempt all parts of this assignment. The assignment will be graded out of total of 46 points. You can use OpenCV and Numpy library functions for all parts of the assignment except stated otherwise. Students are expected to write their own code. (Academic integrity guidelines can be found at https://www.mcgill.ca/students/srr/ academicrights/integrity). Assignments received up to 24 hours late will be penalized by 30%. Assignments received more than 24 hours late will not be graded.

Submission Instructions

    1. Submit a single jupyter notebook consisting of the solution of the entire assignment.

    2. Comment your code appropriately.

    3. Do not forget to run Markdown cells.

    4. Do not submit input/output images. Output images should be displayed in the jupyter notebook itself. Assume input images are kept in the same directory as the codes.

    5. Make sure that the submitted code is running without error. Add a README le if required.

    6. If external libraries were used in your code please specify their name and version in the README le.

    7. We are expecting you to make a path variable at the beginning of your codebase. This should point to your working local (or google drive) folder.

Ex. If you are reading an image as following: img = cv2.imread(’/content/drive/My


1





Drive/Assi 2/images/Circles.png’), Then you should convert it into the

following: path = ’/content/drive/My Drive/Assi 2/images/’ img=cv2.imread(path+’Circles.png’).


Your path variable should be de ned at the top of your jupyter notebook. While grading, we are expecting that we just have to change the path vari-able once and it should allow us to run your solution smoothly. Specify, your path variable in the README le.

    8. Answers to reasoning questions should be comprehensive but concise.

    9. Submissions that do not follow the format will be penalized 10%.













































2





Note: For this assignment, we will work with grayscale images. DO NOT forget to convert your images to GrayScale from RGB images.

    • 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. No for loops are allowed to traverse through the image.













(a)    (b)

Figure 1: (a) Input image for thresholding, (b) Example of output image of thresholding. Note that only numbers "123", "326", "25", and "2014" are segmented (background pixels).



3





    1. Threshold the image at three di erent thresholds a) 80 b) 140 and c) 200 using simple binary thresholding as de ned above. Display the 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. a) T1=60 and T2=110, b) T1=60 and T2=150, c) T1=90 and T2=150. 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 parameters (here, the threshold values) for any of the above-mentioned thresholding methods, such that we get the desired output. Find a threshold value such that only the numbers "123", "326", "2014", and "25" are segmented (i.e. considered as background - black pixel - 0 value). See Figure 1(b). Report your ndings and display the corresponding thresholded images for at least three di erent threshold values, and write how it helped you in narrowing down the desired parameter value. Note that the emphasis is not to get the exact output but to explore di erent parameters and report your ndings. (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 the lecture slides on Image ltering covered during class. For han-dling boundary conditions, you are expected to use zero padding (covered during the lecture/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 the ltered image along with the original image (you can use openCV/scikit-learn function for computing the gaussian lter). (2 points)



4





















(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.


    2. Filter the noisy image using a box lter of the same size. Display the ltered image along with original image. (2 points)

    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 pre-vious question. Display the ltered image along with the original image. (2 points)

    5. Filter the noisy image using a median lter of the same size. Display the ltered image along with the 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.


5

















(a)    (b)

Figure 3: "Circles" [2]: Input image for edge detection.  (a) clean image (b)

image corrupted with Gaussian noise.


    • Apply three di erent versions of the Sobel edge detector with kernel sizes 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 the ltered image. Display the phase (gradient orientation), magnitude, and thresholded images for the 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 a 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. Dis-play phase (gradient orientation), 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 (gradient orientation), magnitude, and thresholded images for di erent thresholds. (3 points)

    • Comment on the e ectiveness of using denoising prior to edge detection. (2 points)









6

More products