[Solved] DIP Assignment 2

$25

File Name: DIP_Assignment_2.zip
File Size: 150.72 KB

SKU: [Solved] DIP Assignment 2 Category: Tag:
5/5 - (1 vote)

1 Download image files[ ]: !wget no-check-certificate https://docs.google.com/uc?,export=download&id=1ktuKqlB6fXrYs_-0tc4TlvDfL0_Xao4i -O Lena.png !wget no-check-certificate https://docs.google.com/uc? ,export=download&id=18fbzSR80lQ6t9rvS67CSIMQBDalYK1Lt -O dog.tif !wget no-check-certificate https://docs.google.com/uc?,export=download&id=1bsKGmmUnVEuQN5XepxjHyQ-qIQjgaZdn -O images.zip!unzip images.zip -d images/2021-04-18 14:14:35-https://docs.google.com/uc?export=download&id=1ktuKqlB6fXrYs_-0tc4TlvDfL0_Xao4iResolving docs.google.com (docs.google.com) 142.250.1.113, 142.250.1.102,142.250.1.101, Connecting to docs.google.com (docs.google.com)|142.250.1.113|:443 connected.HTTP request sent, awaiting response 302 Moved TemporarilyLocation: https://doc-14-3c-docs.googleusercontent.com/docs/securesc/ha0ro937gcu c7l7deffksulhg5h7mbp1/8dgf4s02ukn0bt87isisv7botfa2fni7/1618755225000/14943465539 724169100/*/1ktuKqlB6fXrYs_-0tc4TlvDfL0_Xao4i?e=download [following] Warning: wildcards not supported in HTTP.2021-04-18 14:14:36 https://doc-14-3c-docs.googleusercontent.com/docs/secur esc/ha0ro937gcuc7l7deffksulhg5h7mbp1/8dgf4s02ukn0bt87isisv7botfa2fni7/1618755225000/14943465539724169100/*/1ktuKqlB6fXrYs_-0tc4TlvDfL0_Xao4i?e=downloadResolving doc-14-3c-docs.googleusercontent.com(doc-14-3c-docs.googleusercontent.com) 142.250.103.132,2607:f8b0:4001:c2b::84Connecting to doc-14-3c-docs.googleusercontent.com(doc-14-3c-docs.googleusercontent.com)|142.250.103.132|:443 connected.HTTP request sent, awaiting response 200 OKLength: 473831 (463K) [image/png]Saving to: Lena.pngLena.png 100%[===================>] 462.73K .-KB/s in 0.005s2021-04-18 14:14:36 (100 MB/s) Lena.png saved [473831/473831]2021-04-18 14:14:36-https://docs.google.com/uc?export=download&id=18fbzSR80lQ6t9rvS67CSIMQBDalYK1LtResolving docs.google.com (docs.google.com) 142.250.1.139, 142.250.1.101,142.250.1.138, Connecting to docs.google.com (docs.google.com)|142.250.1.139|:443 connected.HTTP request sent, awaiting response 302 Moved TemporarilyLocation: https://doc-0g-3c-docs.googleusercontent.com/docs/securesc/ha0ro937gcu c7l7deffksulhg5h7mbp1/3de2bg4jp14por2lmgrll9q6h8bfe7v9/1618755225000/14943465539 724169100/*/18fbzSR80lQ6t9rvS67CSIMQBDalYK1Lt?e=download [following] Warning: wildcards not supported in HTTP.2021-04-18 14:14:37 https://doc-0g-3c-docs.googleusercontent.com/docs/secur esc/ha0ro937gcuc7l7deffksulhg5h7mbp1/3de2bg4jp14por2lmgrll9q6h8bfe7v9/1618755225000/14943465539724169100/*/18fbzSR80lQ6t9rvS67CSIMQBDalYK1Lt?e=downloadResolving doc-0g-3c-docs.googleusercontent.com(doc-0g-3c-docs.googleusercontent.com) 142.250.103.132,2607:f8b0:4001:c2b::84Connecting to doc-0g-3c-docs.googleusercontent.com(doc-0g-3c-docs.googleusercontent.com)|142.250.103.132|:443 connected.HTTP request sent, awaiting response 200 OKLength: 58400 (57K) [image/jpeg]Saving to: dog.tif dog.tif 100%[===================>] 57.03K .-KB/s in 0.001s2021-04-18 14:14:38 (90.6 MB/s) dog.tif saved [58400/58400]2021-04-18 14:14:38-https://docs.google.com/uc?export=download&id=1bsKGmmUnVEuQN5XepxjHyQ-qIQjgaZdnResolving docs.google.com (docs.google.com) 142.250.1.138, 142.250.1.102,142.250.1.139, Connecting to docs.google.com (docs.google.com)|142.250.1.138|:443 connected.HTTP request sent, awaiting response 302 Moved TemporarilyLocation: https://doc-10-3c-docs.googleusercontent.com/docs/securesc/ha0ro937gcu c7l7deffksulhg5h7mbp1/limto7vu1cansl8cj5icebss942gqi11/1618755225000/14943465539 724169100/*/1bsKGmmUnVEuQN5XepxjHyQ-qIQjgaZdn?e=download [following] Warning: wildcards not supported in HTTP.2021-04-18 14:14:38 https://doc-10-3c-docs.googleusercontent.com/docs/secur esc/ha0ro937gcuc7l7deffksulhg5h7mbp1/limto7vu1cansl8cj5icebss942gqi11/1618755225000/14943465539724169100/*/1bsKGmmUnVEuQN5XepxjHyQ-qIQjgaZdn?e=downloadResolving doc-10-3c-docs.googleusercontent.com(doc-10-3c-docs.googleusercontent.com) 142.250.103.132,2607:f8b0:4001:c2b::84Connecting to doc-10-3c-docs.googleusercontent.com(doc-10-3c-docs.googleusercontent.com)|142.250.103.132|:443 connected.HTTP request sent, awaiting response 200 OKLength: 595700 (582K) [application/zip]Saving to: images.zipimages.zip 100%[===================>] 581.74K .-KB/s in 0.005s2021-04-18 14:14:38 (124 MB/s) images.zip saved [595700/595700]Archive: images.zip inflating: images/dog.tif inflating: images/hdraw.png inflating: images/hdraw_0.png inflating: images/hdraw_1.png inflating: images/hdraw_2.png inflating: images/hdraw_3.png inflating: images/hdraw_4.png inflating: images/hdraw_5.png inflating: images/hdraw_6.png inflating: images/hdraw_7.png inflating: images/hdraw_9.png inflating: images/Lena.png inflating: images/Lena_left_eye.png2 Question 1Download Lena color image convert it to grayscale image and add salt and pepper noise with noise quantity 0.1,0.2 upto 1 and generate 10 noisy images. a) Do average filtering ( by correlating with average filter ) of varying sizes for each image. Filter size can be 33, 55, 77. (In 33 filter all the values are 1/9, in 55 filter all the values are 1/25 and in 77 filter all the values are 1/49) b) Similarly, repeat the question 1.a by replacing the average filter by median filter.

% error: correlation: 0.0

[[0.11111111 0.11111111 0.11111111][0.11111111 0.11111111 0.11111111][0.11111111 0.11111111 0.11111111]] avg filter window for window size 5:[[0.04 0.04 0.04 0.04 0.04][0.04 0.04 0.04 0.04 0.04][0.04 0.04 0.04 0.04 0.04][0.04 0.04 0.04 0.04 0.04][0.04 0.04 0.04 0.04 0.04]] avg filter window for window size 7:[[0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816][0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816 0.02040816]]

3 Question 2

3.1 Part aConsider the image the attached named as hdraw.png and crop each of the characters from the image and consider that as the sub-image. Find the location of the sub-image in the original by using correlation.

3.2 Part bDownload Lena color image convert it to grayscale image and crop the left eye of Lena as subimage and do the cross-correlation (Normalized correlation) to find the location of the left eye in the original image.

4 Question 3Write a function to implement FFT for 1D signal.

FFT using user-defined function:[(28+0j), (-4+9.65685424949238j), (-4.000000000000001+4j),(-4.000000000000002+1.6568542494923797j), (-4+0j),(-3.9999999999999996-1.6568542494923797j), (-3.999999999999999-4j),(-3.999999999999998-9.65685424949238j)]FFT using numpy implementation:[28.+0.j -4.+9.65685425j -4.+4.j -4.+1.65685425j-4.+0.j -4.-1.65685425j -4.-4.j -4.-9.65685425j]% Error = -1.3322676295501878e-135 Question 4Implement DFT function for an image using the FFT for 1D signal using question 3.

[[424. +0.j -80.+80.j -80. +0.j -80.-80.j][ -8. +8.j 0. +0.j 0. +0.j 0. +0.j][ -8. +0.j 0. +0.j 0. +0.j 0. +0.j][ -8. -8.j 0. +0.j 0. +0.j 0. +0.j]]FFT using numpy implementation:[[424. +0.j -80.+80.j -80. +0.j -80.-80.j][ -8. +8.j 0. +0.j 0. +0.j 0. +0.j][ -8. +0.j 0. +0.j 0. +0.j 0. +0.j][ -8. -8.j 0. +0.j 0. +0.j 0. +0.j]]% Error = -8.881784197001252e-146 Question 5Consider the images of lena and dog images attached. Find phase and magnitude of the dog and lena images using DFT function implemented in question 4.[ ]: import matplotlib.pyplot as plt from google.colab.patches import cv2_imshowView the fourier transformed image along with phase and magnitude parts of the ,transform.Since it is not possible to view complex values in an image, the functions,default to taking the real part of the pixel values and where ever needed, clip the value to the ,range [0, 255] def view_fourier(img):img_FFT = FFT_2D(img)fig,elements=plt.subplots(nrows=2,ncols=4,figsize=(30,15))phase = np.angle(img_FFT, deg=True) magnitude = np.log(np.abs(img_FFT))elements[0,0].imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) elements[0,0].set_title(Original Image, fontsize=30) elements[0,1].imshow(np.real(img_FFT.clip(0, 255)), cmap=gray) elements[0,1].set_title(Fourier Transform, fontsize=30) elements[0,2].imshow(phase, cmap=gray) elements[0,2].set_title(Phase, fontsize=30) elements[0,3].imshow(magnitude, cmap=gray) elements[0,3].set_title(Magnitude, fontsize=30)img_FFT_shifted = np.fft.fftshift(img_FFT) phase_shifted = np.angle(img_FFT_shifted, deg=True)magnitude_shifted = np.log(np.abs(img_FFT_shifted)) # Normalizing the,matrix for visual purposeselements[1,0].imshow(img, cmap=gray)elements[1,0].set_title(Original Image, fontsize=30)elements[1,1].imshow(np.real(img_FFT_shifted.clip(0, 255)), cmap=gray) elements[1,1].set_title(Fourier Transform (center shifted), fontsize=30) elements[1,2].imshow(phase_shifted, cmap=gray) elements[1,2].set_title(Phase (center shifted), fontsize=30) elements[1,3].imshow(magnitude_shifted, cmap=gray) elements[1,3].set_title(Magnitude (center shifted), fontsize=30)plt.show()[ ]: lena = cv2.imread(Lena.png, 0) view_fourier(lena)

7 Question 6 and 7Swap phase of dog image and lena image and display the output.

[0 1 2 3 4 5 6 7][(28+0j), (-4+9.65685424949238j), (-4.000000000000001+4j),(-4.000000000000002+1.6568542494923797j), (-4+0j), (-3.9999999999999996-1.6568542494923797j), (-3.999999999999999-4j),(-3.999999999999998-9.65685424949238j)][0.+0.00000000e+00j 1.-2.71834567e-16j 2.+4.44089210e-16j3.+3.82856870e-16j 4.+0.00000000e+00j 5.-4.97899625e-17j6.-4.44089210e-16j 7.-6.12323400e-17j][ ]: lena = cv2.imread(Lena.png, 0) dog = cv2.imread(dog.tif, 0) dog = cv2.resize(dog, (512, 512)) # resizing so that dims are equal to,2^n.# (512, 512) is chosen since lena image ,is of size (512, 512)lena_FFT = FFT_2D(lena) dog_FFT = FFT_2D(dog)lena_magnitude = np.absolute(lena_FFT) lena_phase = np.angle(lena_FFT)dog_magnitude = np.absolute(dog_FFT) dog_phase = np.angle(dog_FFT)lena_mag_dog_phase_FFT = rect_to_polar_vec(lena_magnitude, dog_phase) lena_mag_dog_phase = IFFT_2D(lena_mag_dog_phase_FFT)dog_mag_lena_phase_FFT = rect_to_polar_vec(dog_magnitude, lena_phase) dog_mag_lena_phase = IFFT_2D(dog_mag_lena_phase_FFT) fig, elements=plt.subplots(nrows=2, ncols=2, figsize=(15, 15))elements[0,0].imshow(cv2.cvtColor(lena, cv2.COLOR_BGR2RGB)) elements[0,0].set_title(Lena Image, fontsize=30) elements[0,1].imshow(cv2.cvtColor(dog, cv2.COLOR_BGR2RGB)) elements[0,1].set_title(Dog Image, fontsize=30) elements[1,0].imshow(np.real(lena_mag_dog_phase), cmap=gray) elements[1,0].set_title(Lena Magnitude Dog Phase, fontsize=30) elements[1,1].imshow(np.real(dog_mag_lena_phase), cmap=gray) elements[1,1].set_title(Dog Magnitude Lena Phase, fontsize=30) plt.show()

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] DIP Assignment 2
$25