高通滤波
低频、高频
频域滤波
代码示例
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('./hanser.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
rows,cols = img.shape
crow,ccol = int(rows/2),int(cols/2)
fshift[crow-30:crow+30,ccol-30:ccol+30] = 0
ishift = np.fft.ifftshift(fshift)
iimg = np.abs(np.fft.ifft2(ishift))
plt.subplot(121),plt.imshow(img,cmap='gray')
plt.title('original'),plt.axis('off')
plt.subplot(122),plt.imshow(iimg,cmap='gray')
plt.title('iimg'),plt.axis('off')
plt.show()
低通滤波
低通滤波器(掩膜)
示例
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('./hanser.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
rows,cols = img.shape
crow,ccol = int(rows/2),int(cols/2)
mask = np.zeros((rows,cols),np.uint8)
mask[crow-30:crow+30,ccol-30:ccol+30] = 1
fshift = mask*fshift
ishift = np.fft.ifftshift(fshift)
iimg = np.abs(np.fft.ifft2(ishift))
plt.subplot(121),plt.imshow(img,cmap='gray')
plt.title('original'),plt.axis('off')
plt.subplot(122),plt.imshow(iimg,cmap='gray')
plt.title('iimg'),plt.axis('off')
plt.show()