�齬6

NumPy(Python+Numeric)��Ȥä�FFT������

�ʲ��Υץ�������¹Ԥ��Ƥߤ褦�� �����ǡ��ѥ�᡼���Ȥ��� U ���Ѥ��Ƥߤ�ȡ��¶��֤Ǥ� ������ȥ��ڥ��ȥ���֤Ǥι�����Ȥδط���Ĵ�٤뤳�Ȥ��Ǥ��롣
f1.py
#!/bin/env python

import Numeric
import FFT
import Gnuplot

gp = Gnuplot.Gnuplot()
gp.title = ('FFT Demo')
gp('set data style lines')

L = 128    # 2�Τ٤���
U = 0.125  # 0.1����0.5���٤��Ѥ��Ƥߤ�
UL = int(L*U)

X = range(L)
f = Numeric.array([1.0]*UL+[0.0]*(L-UL))
d = Gnuplot.Data(X,f,title='Original Function')
gp.plot(d)

raw_input('Press Return')

F = FFT.fft(f)
Fr = Gnuplot.Data(X,F.real,title='FFT Real part')
Fi = Gnuplot.Data(X,F.imag,title='FFT Imaginary part')
gp.plot(Fr,Fi)

raw_input('Press Return')

2����FFT

2������FFT���Ƥߤ褦��
f2.py
#!/bin/env python

import Numeric
import FFT
import Gnuplot

gp = Gnuplot.Gnuplot()
gp.title = ('FFT Demo')
gp('set data style lines')

L = 32     # 2�Τ٤���
U = 0.125  # 0.1����0.5���٤��Ѥ��Ƥߤ�
UL = int(L*U)

X = range(L)
f = Numeric.array([1.0]*UL+[0.0]*(L-UL))
f = Numeric.outerproduct(f,f)
d = Gnuplot.GridData(f,X,X,title='Original Function')
gp.splot(d)
raw_input('Press Return')

F = FFT.fft2d(f)
Fr = Gnuplot.GridData(F.real,X,X,title='FFT Real part')
Fi = Gnuplot.GridData(F.imag,X,X,title='FFT Imaginary part')
gp.splot(Fr,Fi)

raw_input('Press Return')

�ºݤβ�����Ŭ��

FFT�η׻������ǿ���2�Τ٤���ΤȤ��˺�Ŭ������Ƥ��롣�����ǡ� ������ʲ��Τ褦��2�Τ٤��襵�����ˤ��Ƥ�����
pnmscale -width=128 -height=128 cloud.pgm > cl.pgm
(�����ϲ���ȤäƤ��ɤ�����PGM����������������Ѥ���)

���Υץ������Ǥϡ�������ǡ����Ȥ��ƥץ��åȤ��� ���� FFT���̤������ڥ��ȥ��ɽ����������ˡ� �ȿ����֤ǤΥե��륿����ݤ��Ƥ�����Ѵ����� �����ˤ�ɽ�����롣�ե��륿���Υѥ�᡼�����Ѥ���� �������ɤΤ褦���Ѳ����뤫��Ĵ�٤ʤ�����
fc.py
#!/bin/env python

import Image
import Numeric,NumTut
import FFT
import Gnuplot

L = 128                   # ����������(L x L)
U = 0.25                  # �ե��륿���Υѥ�᡼��
im = Image.open('cl.pgm') # �����ե�����

f  = Numeric.array(im.getdata())
f.shape = (L,L)
X = range(L)

gp = Gnuplot.Gnuplot()
gp('set data style lines')

d = Gnuplot.GridData(f,X,X,title='Original Data')
gp.splot(d)
raw_input('Press Return')
F = FFT.fft2d(f)
Fr = Gnuplot.GridData(F.real,X,X,title='FFT Real part')
Fi = Gnuplot.GridData(F.imag,X,X,title='FFT Imaginary part')
gp.splot(Fr,Fi)
raw_input('Press Return')

UL = int(L*U)
G = Numeric.array([1.0]*(UL/2)+[0.0]*(L-UL)+[1.0]*(UL/2))
G = Numeric.outerproduct(G,G)
F = F * G
f = FFT.inverse_fft2d(F)
NumTut.view(Numeric.transpose(f.real))
�Ǹ�ˡ�xv��save��ǽ��Ȥä�ɽ�����줿��������¸���ƥ�ݡ��Ⱥ������Ѥ��뤳�ȡ�

���߹��ߤˤ��ե��륿��

FFT�λ���Ѥ�������(������Ǥ�cl.pgm)��5x5������̲�ե��륿�� (�轵�μ����򻲾�)�򤫤��Ƥ��θ��̤�Ĵ�٥�ݡ��Ȥˤ��ʤ�����
�����α齬�Υ�ݡ��Ȥ� ~/public_html/image/ex6.html �˺������뤳�ȡ�

���͡�
Numerical Python Manual
Gnuplot.py
Python Imaging Library