Generate optical Fourier Spectrum from DFT data.
Generate the logarithm of the magnitude of F, shifted so that the origin stays at the center of the image. The objective of this function is to provide DFT spectrum visualization.
In [1]:
import numpy as np
def dftview(F):
import ia898.src as ia
FM = ia.dftshift(np.log(np.abs(F)+1))
return ia.normalize(FM).astype(np.uint8)
In [1]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python dftview.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 [2]:
if testing:
import matplotlib.image as mpimg
import numpy.fft as FFT
f = mpimg.imread('../data/cameraman.tif')
ia.adshow(f, "Original 2D image - Cameraman")
F = FFT.fft2(f)
Fv = ia.dftview(F)
ia.adshow(Fv, "Cameraman DFT optical spectrum")
In [3]:
if testing:
print('testing dftview')
print(repr(ia.dftview(np.array([[10+6j,20+5j,30+4j],[40+3j,50+2j,60+1j]]))) == repr(np.array(
[[254, 190, 226],
[146, 0, 86]],np.uint8)))