diff --git a/Image_Manipulations/fourier transform/code.py.html b/Image_Manipulations/fourier transform/code.py.html new file mode 100644 index 0000000..17dcaa3 --- /dev/null +++ b/Image_Manipulations/fourier transform/code.py.html @@ -0,0 +1,14859 @@ + + +
+ + +import cv2
+
import numpy as np
+
import matplotlib.pyplot as plt
+
img = cv2.imread('C:/Users/Kriti/OneDrive/Desktop/college/robotics/fr.png', 0)
+
float32_img = np.float32(img)
+
dft_img = cv2.dft(float32_img, flags=cv2.DFT_COMPLEX_OUTPUT)
+
dft_img_ce = np.fft.fftshift(dft_img)
+
img_dft = 20 * np.log(cv2.magnitude(dft_img_ce[:, :, 0], dft_img_ce[:, :, 1]))
+
plt.subplot(121)
+plt.imshow(img, cmap='gray')
+plt.subplot(122)
+plt.imshow(img_dft, cmap='gray')
+plt.show()
+
#low pass
+
img = cv2.imread('C:/Users/Kriti/OneDrive/Desktop/college/robotics/fr.png', 0)
+
img_float = np.float32(img)
+
dft = cv2.dft(img_float, flags=cv2.DFT_COMPLEX_OUTPUT)
+
dft_center = np.fft.fftshift(dft)
+
crow, ccol = int(img.shape[0] / 2), int(img.shape[1] / 2)
+
mask = np.zeros((img.shape[0], img.shape[1], 2), np.uint8)
+
mask[crow-30:crow+30, ccol-30:ccol+30] = 1
+
mask_img = dft_center * mask
+
img_idf = np.fft.ifftshift(mask_img)
+
img_idf = cv2.idft(img_idf)
+
img_idf = cv2.magnitude(img_idf[:, :, 0], img_idf[:, :, 1])
+
plt.subplot(121)
+plt.imshow(img, cmap='gray')
+plt.subplot(122)
+plt.imshow(img_idf, cmap='gray')
+plt.show()
+
#high pass
+
img = cv2.imread('C:/Users/Kriti/OneDrive/Desktop/college/robotics/fr.png', 0)
+
img_float = np.float32(img)
+
dft = cv2.dft(img_float, flags=cv2.DFT_COMPLEX_OUTPUT)
+
dft_center = np.fft.fftshift(dft)
+
crow, ccol = int(img.shape[0] / 2), int(img.shape[1] / 2)
+
mask = np.ones((img.shape[0], img.shape[1], 2), np.uint8)
+
mask[crow-30:crow+30, ccol-30:ccol+30] = 0
+
mask_img = dft_center * mask
+
img_idf = np.fft.ifftshift(mask_img)
+
img_idf = cv2.idft(img_idf)
+
img_idf = cv2.magnitude(img_idf[:, :, 0], img_idf[:, :, 1])
+
plt.subplot(121)
+plt.imshow(img, cmap='gray')
+plt.subplot(122)
+plt.imshow(img_idf, cmap='gray')
+plt.show()
+
+