def generateImg(): f = np.zeros([512, 512], dtype=np.float) f[225:285, 250:260] = 1 return f if __name__ == '__main__': plt.figure() #产生图像 f = generateImg() plt.subplot(2, 2, 1) plt.imshow(f, 'gray') #fft变换 f_fft = Q1.dft2D(f) plt.subplot(2, 2, 2) plt.imshow(np.abs(f_fft), 'gray') #中心化 F = np.fft.fftshift(f_fft) plt.subplot(2, 2, 3) plt.imshow(np.abs(F), 'gray') #对数变换 s = np.log(1 + np.abs(F)) plt.subplot(2, 2, 4) plt.imshow(s, 'gray') plt.show()
''' @author: shibaorong @license: (C) Copyright 2019, Node Supply Chain Manager Corporation Limited. @contact: [email protected] @software: pycharm @file: Q3.py @time: 2019/10/12 16:57 @desc: ''' import Q1 import Q2 import cv2 import matplotlib.pyplot as plt import numpy as np def normalization(f): return f / 255.0 if __name__ == '__main__': f = cv2.imread('rose512.tif', 0) f = normalization(f) F = Q1.dft2D(f) g = Q2.idft2D(F) d = f - g fimg = np.abs(d) plt.imshow(fimg, 'gray') plt.show()
@license: (C) Copyright 2019, Node Supply Chain Manager Corporation Limited. @contact: [email protected] @software: pycharm @file: Q2.py @time: 2019/10/12 16:17 @desc: ''' import Q1 import numpy as np import cv2 import matplotlib.pyplot as plt def idft2D(F): F_shape=F.shape F=F.conj() F=np.fft.fft(F,axis=-2) F = np.fft.fft(F, axis=-1) F/=F_shape[0]*F_shape[1] F=F.conj() return F if __name__=='__main__': F = cv2.imread('rose512.tif', 0) #plt.imshow(F/255.0, 'gray') F=Q1.dft2D(F) C=idft2D(F) fimg = np.abs(C) plt.imshow(fimg, 'gray') plt.show()