In [1]:
import numpy as np
def idft(F):
import ia898.src as ia
s = F.shape
if F.ndim == 1: F = F[np.newaxis,np.newaxis,:]
if F.ndim == 2: F = F[np.newaxis,:,:]
(p,m,n) = F.shape
A = ia.dftmatrix(m)
B = ia.dftmatrix(n)
C = ia.dftmatrix(p)
Faux = np.conjugate(A).dot(F)
Faux = Faux.dot(np.conjugate(B))
f = np.conjugate(C).dot(Faux)/(np.sqrt(p)*np.sqrt(m)*np.sqrt(n))
return f.reshape(s)
In [2]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python idft.ipynb
import numpy as np
import sys,os
import matplotlib.image as mpimg
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [3]:
if testing:
f = np.arange(24).reshape(4,6)
F = ia.dft(f)
g = ia.idft(F)
print(np.round(g.real))
In [4]:
if False: #testing:
import matplotlib.image as mpimg
f = mpimg.imread('../data/cameraman.tif')
F = ia.dft(f)
print(F.shape)
H = ia.circle(F.shape, 50,[F.shape[0]/2,F.shape[1]/2] )
H = ia.normalize(H,[0,1])
FH = F * ia.idftshift(H)
print(ia.isdftsym(FH))
g= ia.idft(FH)
ia.adshow(f)
ia.adshow(ia.dftview(F))
ia.adshow(ia.normalize(H,[0,255]))
ia.adshow(ia.dftview(FH))
ia.adshow(ia.normalize(abs(g)))
In [ ]: