Tags:
create new tag
view all tags

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.

Sunflower galaxy m63



Below is the image in RGB and the 2D Fourier Transformation.

-- Public.RyanCheale - 28 Dec 2013

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r1 - 28 Dec 2013 - RyanCheale

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback