Sie sind auf Seite 1von 11

FOURIER

TRANSFORM

16/10/2008 A Java Advanced Imaging Implementation

This article presents the implementation of the Fourier


transform using the Java API JAI. This API is very powerful in
the construction of image processing applications.
Fourier Transform

Fourier Transform
INTRODUCTION

The French mathematician Baptiste Joseph Fourier (1768-1830) developed the known Fourier
transform when studying the heat propagation theory (Fourier, 2003). He considered that, the heat,
as well as gravity, infiltrate in each universe substance, and its primary cause is subject to constant
and simple laws. Starting with this reckoning, he developed the mathematical laws of heat
diffusion, obeyed by the elements. One of his main concerns was the terrestrial temperature, so
much so it is awarded to him the paternity of the term “greenhouse effect”, effet de serre (Prestini,
2003).

The goal of this document is the Java implementation of the discrete Fourier transform and its
inverse, with the Java Advanced Imaging (JAI) application program interface (API), for mapping
between the spatial and frequency domains in digital images. The Fourier transform utility, among
other things, is its function as a filter, operating as low and high pass.

Generally, “Fourier analysis” means the use of Fourier “series” and “transforms”, being useful in
several fields of mathematics, physics, biology etc. In vector calculus, for instance, a vector v is an
entity with the length and direction properties. Usually, we do not do vector calculus directly with
these properties, but using the vector’s components. For example, in 2D space, they would be (v1,
v2). The length, or modulus, of v is calculated as:

v  v12  v22

These components are the coefficients of the only representation of v as a linear combination of
vectors in the standard base [i, j]:

v = v1i + v2j

As each vector can be represented this way and as [i, j] is a simple basis (their elements are
orthogonal and of unitary length), vector manipulation can be simplified to direct calculations with
each vectors components. Similarly, when Fourier was describing mathematically the heat
conduction process, he considered working with a linear combination of several elements. For the
heat conduction in a uniform, finite length rod, he represented the temperature, u, in the x position
in the rod, u(x), in determined time, subject to certain initial and boundary conditions as:

Page 1
Fourier Transform

u ( x)  a0  a1 cos(cx)  b1 sin( cx)  a2 cos(2cx)  b2 sin( 2cx) 


(1)
a3 cos(3cx)  b3 sin(3cx)  

Where c is  divided by the rod’s length, and the ak’s and b k’s are constants to be determined after
conditioning this representation to u in the equations modeling the heat flow. Fourier’s approach
was correct1, and his idea of representing a function as sine and cosines lead to the development of
several mathematical applications (Howell, 2001).

FOURIER SERIES AND TR ANSF ORMS

If the initial temperature distribution, f(t, ) = f(0, ), is given, this problem is knows as initial
condition problem, for the heat equation (2). Fourier proposed a linear solution to the problem,
expanding the initial distribution of temperature as a trigonometric series.

In the lecture that Fourier presented in the French Academy, December 1807, he stated that any
arbitrary function, defined in a finite interval, can be expressed as a summation of sine and cosine
functions. The validity of the theorem was steadily extended and accepted with the works from
Dirichlet, 1829 (Johann Peter Gustav Lejeune Dirichlet, 1805-1859), Riemann, 1854 (Georg
Friedrich Bernhard Riemann, 1826-1866), Lipót Fejér, 1904 (Lipót Fejér, 1880–1959), and
Lebesgue, 1905 (Henri Léon Lebesgue, 1875-1941), compiled by O’ Connor & Robertson (2006).
The validity of Fourier series was conditioned only by the integrability of the function f()
(Kanasewich, 1981).

Consider a tiny, circular ring. To simplify, consider its length as 2. Let  be the variable that
determines the position in the ring (angle in radians), such that  and  + 2 give the same position
in the ring. The temperature in time t and the position  is defined by f(t, ). The heat flow in the
ring is given by the following differential partial equation (Jayakumar, 1998):

f  2 f
 (2)
t  2

1
According to Duddeck (2002), Fourier submitted his paper On the propagation of heat in solid bodies to Paris Institute
in December, 21st, 1807, being criticized by the scientific committee (Lagrange, Laplace, Monge and Lacroix).
Lagrange and Laplace objection concerned the function’s expansion as trigonometric series, knows as Fourier series.
His work became known from 1822, with the Théorie Analytique de la Chaleur publication.

Page 2
Fourier Transform

If the initial temperature distribution, f(t, ) = f(0, ), is given, this problem is knows as initial
condition problem, for the heat equation (2). Fourier proposed a linear solution to the problem,
expanding the initial distribution of temperature as a trigonometric series.

In the lecture that Fourier presented in the French Academy, December 1807, he stated that any
arbitrary function, defined in a finite interval, can be expressed as a summation of sine and cosine
functions. The validity of the theorem was steadily extended and accepted with the works from
Dirichlet, 1829 (Johann Peter Gustav Lejeune Dirichlet, 1805-1859), Riemann, 1854 (Georg
Friedrich Bernhard Riemann, 1826-1866), Lipót Fejér, 1904 (Lipót Fejér, 1880–1959), and
Lebesgue, 1905 (Henri Léon Lebesgue, 1875-1941), compiled by O’ Connor & Robertson (2006).
The validity of Fourier series was conditioned only by the integrability of the function f()
(Kanasewich, 1981).

Fourier developed the idea to find the solution of the heat equation, as differential partial equations
with initial and boundary conditions (2). The Fourier series of a function f(), defined in the
interval (-I, I), is given by Debnath (2002)2:

 in 
f ( )  c
n  
n exp
 l 
 (3)

And the Fourier coefficients, already known by Euler in 1777 (Leonhard Euler, 1707-1783), as the
following integrals formulas:

t
1  in 
cn   f ( ) exp    d (4)
2l  t  l 

Where i   1 . The Fourier series represents the resolution of a given function in an infinity set,
but discrete, of harmonic components. There is also the continuous form of the Fourier series, not
showed here. The Fourier series and integrals, and its applications, were the main issues of his
treatise published in 1822. The main issue about the convergence of the Fourier series was solved
by Carleson in 1966 (Lennart Axel Edvard Carleson, 1928-), who proofed that these series of a
continuous function almost always are convergent (Debnath, 2002).

a0 k
2
Considering sine and cosine: f (t )    (ar cos rt  br sen rt ) , as of:
2 r 1
1  1  1 
a0  
 
f (t ) dt , ar  
 
f (t ) cos rtdt e br   f (t ) sen rtdt
 

Page 3
Fourier Transform

The Fourier transform descended from the theorem of the Fourier integral, sustained in his treatise
Théorie analytique de la chaleur. The Fourier series and transforms are acknowledged as one of the
most important mathematic discoveries, with a wide application front in several scientific fields.
Much of these applications use the Fourier transform in the time and frequency domains. The
Fourier transform of a signal, or function f(t), is defined as (Debnath, 2002):


( f (t ))  fˆ ( )   f (t ) exp( it )dt  f , e 
iwt
(5)


Where fˆ ( ) is the Fourier transform with variable  or a frequency function , and f , eit  is the
inner product in a Hilbert space. The transformation of a signal divides it in a sine wave with
different frequencies and phases, commonly knows as Fourier spectrum (Debnath, 2002).
Materially, the Fourier integral measures the f oscillation in  frequency, and fˆ ( ) is called
frequency spectrum of the signal or wave f(t). One can call f(t) as a wave form in the time domain
and fˆ ( ) as the wave form in the frequency domain. This terminology describes the duality and
the equivalence of the waves forms representation.

The success of the Fourier transform was due to the fact that, under certain conditions, the signal
f(t) can be reconstructed with the inverse Fourier transform formula:

1 1
f (t )   1{ fˆ ( )}   fˆ ( ) exp(it )d  2 fˆ , e 
 iwt
(6)
2 

According to Champeney (1987), Fourier didn’t give, precisely, a set of conditions under what the
inversion theorem could happen. His legacy is based upon the discovery and demonstration of how
the theorem could be useful in applications related to physics problems, being burdened to
subsequent mathematicians to add rigor in Fourier ideas. Actually, the “Fourier theorem” consists
not only of a sole theorem, but in several theorems, all about a common theme.

To Champeney (1987), a lot of things depend on how one interprets the integral symbol in these
theorems. It is necessary to decide between Lebesgue or Riemann integration. Each interpretation
comes up with its own theorems. This way, it is mandatory to recognize that the own definition of
what one could understand by the Fourier transform, becomes uncertain. The initial developments
of the Fourier transform used the Riemann integration theory. An alternative approach for this
integration, developed by Lebesgue, is more powerful and simple to use, respect to the Fourier
theorem, and virtually all the modern mathematical approach uses the Lebesgue theory.

Page 4
Fourier Transform

Fundamentally, the difference between the integration processes of Lebesgue versus Riemann is:
the Lebesgue integral considers infinity integration limits and certain infinity singularities all in one
simple limit process, whilst the Riemann integral is not able to deal with infinity limits of
integration or with infinities functions singularities. Functions with singularity are either infinity or
do not have finite derivatives in all intervals. Singularity is a point where an equation, surface or
function degenerates (a limit issue in which a class of objects changes its nature, then belonging to
other class of objects, normally, simpler). Singularities are also known as singular points.

As shown in (5) and (6), the Fourier transform (FT) and its inverse (IFT), need two modifications
for use in digital image processing: (1) use the two dimensional plane or spatial domain; and (2) use
a discrete version. The discrete version of the Fourier transform (DFT) is given as (Myler & Weeks,
1993):

M 1 N 1
1   ux vy 
F (u , v ) 
MN
 f ( x, y ) exp  i 2  M  
N 
(7)
x  0 y 0 

Where M is the number of pixel in the x direction, N is the number of pixel in the y direction, u = 0,
1, 2,, M – 1; and v = 0, 1, 2,, N – 1. The inverse Fourier transform is given as (Myler & Weeks,
1993):

M 1 N 1
  ux vy 
f ( x, y)   F (u , v) exp i 2    (8)
u 0 v  0   M N 

With x = 0, 1, 2,, M – 1, and y = 0, 1, 2,, N – 1.

The equations (7) and (8) show that the transform of a image M  N yields a matrix M  N of
coefficients. As the inverse transform rebuilds the original image using these coefficients, they must
build a complete representation of the information contained in the image. The Fourier transform
manages the image in the frequency domain and the inverse maps the image back to the spatial
domain. When working with digital images, a variant of the above equations, named fast Fourier
transform (FFT), is used, based upon the separability property (Gonzalez & Wintz, 1977; Lyon,
1999).

Page 5
Fourier Transform

JAVA ADVANCED IMAGING (JAI)

JAI classes, or API, are not found in the standard J2SDK package. It is necessary to download them
from the web site:

http://java.sun.com/products/java-media/jai

Besides the JAI package, the above site has the API documentation, JAI developers community
help addresses, and a tutorial.

JAI has two main operators to work with the Fourier frequency domain: DFT and IDFT. The discrete
Fourier transform (DFT) operator creates an image in the frequency domain with complex data,
where the even bands represent the real domain, and the odd bands represent the imaginary domain
of the Fourier transform.

This means that each pixel in the frequency domain has a magnitude and a phase angle, so as to say
that the generated band quantity in this domain is twice the number in the spatial domain. The
mapping from the frequency to the spatial domain is accomplished using the inverse discrete
Fourier transform (IDFT). In addition to these operators, there are some that work the complex side
of the image: Magnitude, MagnitudeSquared, Phase and PeriodicShift

The Magnitude operator computes each pixel’s magnitude or amplitude spectrum from the complex
image. The source image must have an even pair of bands (2, 4 etc.), representing the real domain
and an odd pair of bands (1, 3 etc.), representing the imaginary domain of each complex pixel. The
MagnitudeSquared operator powers by two each magnitude pixel, yielding the potency spectrum.

These operators’ implementations are:


public PlanarImage imagemMagnitude(PlanarImage dft) {

System.out.println("Creating magnitude image...");

ParameterBlock pb = new ParameterBlock();

pb.addSource(dft);

return JAI.create("magnitude", pb);

Page 6
Fourier Transform

// Compute the potency spectrum

public PlanarImage imagemQuadradoMagnitude(PlanarImage dft) {

System.out.println("Creating squared magnitude...");

ParameterBlock pb = new ParameterBlock();

pb.addSource(dft);

return JAI.create("magnitudeSquared", pb);

The Phase operator computes the phase angle of each complex image pixel. It uses the even and
odd bands set, a DFT image. The implementation code is:

public PlanarImage imagemFase(PlanarImage dft) {

System.out.println("Creating phase image...");

ParameterBlock pb = new ParameterBlock();

pb.addSource(dft);

return JAI.create("phase", pb);

Another JAI frequency operator is PeriodicShift, that computes the periodic image translation in
the x and/or y direction. This operator is used to make a translation in the amplitude spectrum
origin, transferring, e.g., the zero frequency to the center of image, an usual procedure when
showing this spectrum:

public PlanarImage imagemDeslocaXY(PlanarImage src, int shiftX,


int shiftY) {

System.out.println("Calculating periodic translation...");

ParameterBlock pb = new ParameterBlock();

pb.addSource(src);

pb.add(shiftX);

pb.add(shiftY);

return JAI.create("periodicShift", pb);

Page 7
Fourier Transform

After obtaining the separated images with the amplitude spectrum and phase, one can apply a low
or high pass filter, or another operation, individually. To show the result of procedures done in the
frequency domain, it is necessary to aggregate again the real and imaginary components, permitting
the use of the IDFT operator. The PolarToComplex operator does this, creating a complex image
from the phase and magnitude images:

// Compute complex image

public PlanarImage imagemPolar2Complex(PlanarImage mag,

PlanarImage phase) {

System.out.println("Creating complex image...");

ParameterBlock pb = new ParameterBlock();

pb.addSource(mag);

pb.addSource(phase);

return JAI.create("polarTocomplex", pb);

The resulting PlanarImage is sent to IDFT, whose function is to rebuild the original image. Fig. 1
shows the process. JAI requires a chain process for the Fourier operators. The picture in Fig. 1
shows the implementation of the program JAIDFT.java. Its purpose is to show the importance of
the information contained in the phase component of the original image. If one erases it, as making
it zero in the example, the reconstruction of the image is damaged, as one can see running the
program.

magnitude

polar para
fonte DFT complexo IDFT resultado

fase fase = 0

Figure 1 JAIDFT.java flowchart

Page 8
Fourier Transform

As shown in the picture, for one to find the Fourier transform of an image, just feed the image name
to DFT. This operator generates two images, representing the magnitude and the phase. These
images synthesize the complex image, created by DFT, in the polar coordinates space, (r, ), being
the magnitude the radial coordinate, r, and the phase, the angular coordinate, . In order to map the
image from the frequency domain back to the spatial domain, the image must be of complex type.
The PolarToComplex operator does this, creating a complex image, from the magnitude and phase
images. From this point on, the IDFT operator is used to generate the result in the spatial domain.

CASE STUDY

Fig. 2 shows the result from the program JAIDFT.java. When the phase information from the
image is turned to zero in the frequency domain, the original image cannot be recovered, showing
that the image decomposition from the spatial domain to the frequency domain store the same
information, although in diverse planes.

Figure 2 JAIDFT.java result

WHERE TO GET THE SOURCE CODE

Source code is available, under the General Public License GNU, from the site:

http://repositorio.agrolivre.gov.br/projects/pid.

Please note: if you intend to use this material in any publication, please give credits to:

Page 9
Fourier Transform

MIRANDA, J. I.; CAMARGO NETO, J. Implementação da transformada de Fourier com o Java


Advanced Imaging. Campinas: Embrapa Informática Agropecuária, 2006. Páginas: 5 (Embrapa
Informática Agropecuária. Comunicado Técnico, 74). Available in:
<http://www.cnptia.embrapa.br/files/ct74.pdf>.

FOR ANY additional information, please contact:

miranda@cnptia.embrapa.br

BIBLIOGRAPHY

CHAMPENEY, D. C. A handbook of Fourier theorems. Cambridge, UK: Cambridge University


Press, 1987. 198p.
DEBNATH, L. Wavelet transformations and their applications. Boston: Birkhäuser, 2002. 588p.
DUDDECK, F. M. E. Fourier BEM: generalization of boundary element methods by Fourier
transform. Berlin: Springer-Verlag, 2002. 183p.
FOURIER, J. B. J. The analytical theory of heat. Mineola, NY: Courier Dover Publications, 2003.
496p.
GONZALEZ, R. C.; WINTZ, P. Digital image processing. Reading, MA: Addison-Wesley
Publishing Co., 1977. 431p.
HOWELL, K. B. Principles of Fourier analysis. Boca Raton, FL: CRC Press, 2001. 792p.
JAYAKUMAR, R. Method of applied Fourier analysis. Boston: Birkhäuser, 1998. 385p.
KANASEWICH, E. R. Time sequence analysis in geophysics. Alberta: University of Alberta,
1981. 480p.
LYON, D. Image processing in Java. Upper Saddle River, NJ: Prentice Hall, 1999. 532p.
MYLER, H. R.; WEEKS, A. R. Computer imaging in C. Englewood Cliffs: Prentice Hall, 1993.
284p.
PRESTINI, E. The evolution of applied harmonic analysis: models of the real world. Boston:
Birkhäuser, 2003. 368p.

Page 10

Das könnte Ihnen auch gefallen