def FFTDemo(self):
img = cv2.imread("lena.jpg")
baseTransfer = BasePixelTransfer.BasePixelTransfer()
img = baseTransfer.RGB2Gray(img)
fimg = img.copy()
fimg = np.float32(fimg)
# for i in xrange(0, img.shape[0]):
# for j in xrange(0, img.shape[1]):
# fimg[i, j] *= (-1) ** (i + j)
fftimg = np.fft.fftshift(np.fft.fft2(fimg))
ifft = np.real(np.fft.ifft2(fftimg))
for i in xrange(0, ifft.shape[0]):
for j in xrange(0, ifft.shape[1]):
ifft[i, j] *= (-1) ** (i + j)
cv2.namedWindow("lena")
cv2.imshow("lena", img)
cv2.namedWindow("fft")
cv2.imshow("fft", np.real(fftimg))
cv2.imshow("ifft", np.uint8(ifft))
cv2.waitKey(0)
评论列表
文章目录