Last active
May 24, 2021 04:06
-
-
Save JustinSDK/34529cdc1ad299e143bc41ab2745f20e to your computer and use it in GitHub Desktop.
二維傅立葉轉換與逆轉換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# 圖片來源:https://openhome.cc/Gossip/DCHardWay/images/Fourier4-1.JPG | |
img = cv2.imread('Fourier4-1.JPG', cv2.IMREAD_GRAYSCALE) | |
f = np.fft.fft2(img) | |
shifted = np.fft.fftshift(f) # 將頻率 (0, 0) 位移至中心 | |
amp = np.abs(shifted) | |
cv2.imshow('FFT 2D', amp / np.max(amp) * 255) # 頻域表示 | |
inversed = np.fft.ifft2(f).real.astype('uint8') # 逆轉換 | |
cv2.imshow('INVERSE FFT 2D', inversed) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment