In [10]:
import numpy as np
import matplotlib.pyplot as plt
import PIL
import cmath
def DFT2D(image):
data = np.asarray(image)
M, N = image.size # (img x, img y)
dft2d = np.zeros((M,N),dtype=complex)
for k in range(M):
for l in range(N):
sum_matrix = 0.0
for m in range(M):
for n in range(N):
e = cmath.exp(- 2j * np.pi * ((k * m) / M + (l * n) / N))
sum_matrix += data[m,n,1] * e
dft2d[k,l] = sum_matrix
return dft2d
#img = PIL.Image.open("example.jpg")
#img2 = img.resize((50,50))
#plt.imshow(img2)
#dft = DFT2D(img2)
#plt.imshow(dft.real)
image = PIL.Image.new('RGBA', size=(50, 50), color=(1, 0, 0))
plt.imshow(image)
Out[10]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: