Fourier Transfrom Script
The below script is used to import an image or .fits file and produce the 2D Fourier Transformation.
import pyfits
import numpy as np
import pylab as py
import os
from PIL import Image
def imageImport() :
#Function to call image files#
#Changes current directory to one of users input#
os.chdir('C:/Users/Ryan/Dropbox/Major Project/python/')
#Imports a picture image#
importImage = Image.open('sun.jpg').convert('L')
imageArray = np.asarray(importImage)
'''
#Import a fits file (requires pyfits)#
image = pyfits.getdata('Dragonfly2_light.fit')
'''
#functions for fourtier transform and plotting#
iF = imageFourier(imageArray)
plotTransform(iF, imageArray)
def imageFourier(imageArray) :
#Function to provide a Fourier Transform of inputted image file#
#2d fourier transform#
fourierTransform = np.fft.fft2(imageArray)
#centre frequency spectrum#
fourierShift = np.fft.fftshift(fourierTransform )
#take absolute values squared#
fourierArray = np.abs(fourierShift)**2
#return the final array#
return fourierArray
def plotTransform(f, imageArray) :
#Function to provide plots#
py.figure(1)
py.clf()
py.imshow(imageArray)
py.figure(2)
py.clf()
py.imshow(np.log(f))
py.show()
imageImport()
Below is the sunflower galaxy, Image used from here.
Below is the image in RGB and the 2D Fourier Transformation.
-- Public.RyanCheale - 28 Dec 2013