Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Nov 29 12:02:11 2021
- @author: Sajid
- """
- import cv2
- import numpy as np
- from matplotlib import pyplot as plt
- def gauss_low_pass_filter(row,col,sigma):
- row = int(row) // 2
- col = int(col) // 2
- x, y = np.mgrid[-row:row, -col:col]
- normal = 1 / (2.0 * np.pi * sigma**2)
- g = np.exp(-((x**2 + y**2) / (2.0*sigma**2))) * normal
- factor = 255/ g.max()
- gaussian_image = g*factor
- print(gaussian_image)
- cv2.imshow('Gaussian Smoothed Image',gaussian_image)
- plt.plot(gaussian_image)
- return g
- img = cv2.imread('download.jpg',0)
- f = np.fft.fft2(img)
- fshift = np.fft.fftshift(f)
- magnitude_spectrum = 20*np.log(np.abs(fshift))
- mag = np.abs(fshift)
- print(mag)
- ang = np.angle(fshift)
- sigma = float(input('Enter Cut Off: '))
- mask = gauss_low_pass_filter(img.shape[0],img.shape[1],sigma)
- combined = np.multiply(mag*mask, np.exp(1j*ang))
- imgCombined = np.real(np.fft.ifft2(np.fft.ifftshift(combined)))
- plt.subplot(121),plt.imshow(img, cmap = 'gray')
- plt.title('Input Image'), plt.xticks([]), plt.yticks([])
- plt.subplot(122),plt.imshow(imgCombined, cmap = 'gray')
- plt.title('Output image'), plt.xticks([]), plt.yticks([])
- #plt.imshow(imgCombined, cmap='gray')
- plt.show()
- cv2.waitKey(0)
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement