This page is about the 2D FFT, also called FFT2 in certain libraries and programming environments.
img = Image.open("/home/leo/kekw.jpg").convert('L')
#img = img.resize((int(img.width / 4), int(img.height / 4)))npimg = np.zeros((img.height, img.width))
for y in range(img.height):
for x in range(img.width):
npimg[y][x] = img.getpixel((x, y))
npimg = npimg / 256
img = npimg
plt.imshow(img, cmap="gray")
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7e92430>
<matplotlib.colorbar.Colorbar at 0x7fbbb7e4d910>
def fft_rows(img):
fft_img = np.zeros(img.shape, dtype=np.complex_)
for y in range(img.shape[0]):
row = [img[y][x] for x in range(img.shape[1])]
row_fft = np.fft.fft(row)
for x, col in enumerate(row_fft):
fft_img[y][x] = col
return fft_img
img = fft_rows(img)
plt.imshow(np.abs(img), vmax=1)
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7dbdfd0>
<matplotlib.colorbar.Colorbar at 0x7fbbb7d62370>
def fft_cols(img):
fft_img = np.zeros(img.shape, dtype=np.complex_)
for x in range(img.shape[1]):
row = [img[y][x] for y in range(img.shape[0])]
row_fft = np.fft.fft(row)
for y, col in enumerate(row_fft):
fft_img[y][x] = col
return fft_img
img = fft_cols(img)
plt.imshow(np.abs(img), vmax=2)
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7c834c0>
<matplotlib.colorbar.Colorbar at 0x7fbbb7ca29d0>
plt.imshow(np.fft.ifft2(img).real, cmap="gray")
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7c38520>
<matplotlib.colorbar.Colorbar at 0x7fbbb7bd5820>
shp = img.shape
img = img.flatten()
decim = 50
for i, x in enumerate(img):
img[i] = int(x.real / decim) * decim + int(x.imag / decim) * decim * 1j
img = img.reshape(shp)
plt.imshow(np.fft.ifft2(img).real, cmap="gray")
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7b754f0>
<matplotlib.colorbar.Colorbar at 0x7fbbb7b119d0>
plt.imshow(np.abs(img), vmax=5)
plt.colorbar()<matplotlib.image.AxesImage at 0x7fbbb7aa66d0>
<matplotlib.colorbar.Colorbar at 0x7fbbb7a42af0>
np.max(img.real)/decim, np.min(img.real)/decim
np.max(img.imag)/decim, np.min(img.imag)/decim
#from collections import Counter
#Counter(img.real.flatten()/decim)
#Counter(img.imag.flatten()/decim)(4590.0, -1974.0)
(645.0, -645.0)