You are on page 1of 29

2.

1 introduction to image processing


The widespread availability of relatively low-cost personal computers has Herald
a revolution in digital image processing activities among scientists and the consumer
population in general. Coupled to digitization of analog images( mainly photographs )
by inexpensive scanners and image acquisition with electronic sensors (primarily
though charge-coupled devices or CDs ), user friendly image-editing software
packages have led to a dramatic increase in the ability to enhance features, extract
information, and to easily modify the properties of a digital image .[2]
Depend on ultimate 'receiver' of the image; one can separate computer imaging into
two fields:
Computer vision: vision humans to perceive and understand the world
surrounding us. Its aims to duplicate the effect of human vision by
electronically perceiving and understanding an image.
Image processing : the following sequence of processing steps is commonly
recognized:[3][1]
 Image Acquisition: it is acquire a digital image to do so require an image
sensor (such as a TV camera, scanner) and digitized.
 Preprocessing: it is used to improve the image and maybe enhances some
object features which are relevant to understanding the image.
 Image segmentation: computer tries to separate objects from the image
background.
 Object description and representation: in a totally segmented image is
also understood as part of low level image processing. Description is also
called feature selection deals with extracting features that result in some
quantitative information of interest or feature that are basic for
differentiating one class of objects from another. It is appropriate when
the focus is on internal properties, such as texture or skeletal shape.

(4)
 Knowledge Base: Knowledge about a problem domain is coded into an
image processing system in the form of Knowledge database. This
Knowledge may be as simple as dialing regions of an image where the
information of interest is known to be located thus limiting the search
that has to be conducting in seeking that information.

2.2 Spatial Domain

For simplicity, assume that the image I being considered is formed by projection from
scene S (which might be a two- or three-dimensional scene, etc.).

The spatial domain is the normal image space, in which a change in position in I
directly projects to a change in position in S. Distances in I (in pixels) correspond to
real distances (e.g. in meters) in S.

This concept is used most often when discussing the frequency with which image
values change, that is, over how many pixels does a cycle of periodically repeating
intensity variations occur. One would refer to the number of pixels over which a
pattern repeats (its periodicity) in the spatial domain.

In most cases, the Fourier Transform will be used to convert images from the spatial
domain into the frequency domain.

A related term used in this context is spatial frequency, which refers to the inverse of
the periodicity with which the image intensity values change. Image features with
high spatial frequency (such as edges) are those that change greatly in intensity over
short image distances. [1]

Another term used in this context is spatial derivative, which refers to how much the
image intensity values change per change in image position.

(5)
2.3 Fourier Transform

This section describes the Discrete Fourier Transform (DFT), that is, a Fourier
Transform as applied to a discrete complex valued series.

Continuous Fourier Transform (CFT)

For a continuous function of one variable f(t), the Fourier Transform F(f) will be
defined as: --------------> 2.1

and the inverse transform as

------------> 2.2

where j is the square root of -1 and e denotes the natural exponent

------------> 2.3

Discrete Fourier Transform (DFT)

Consider a complex series x(k) with N samples of the form

------------> 2.4

where x is a complex number

------------> 2.5

Further, assume that the series outside the range 0, N-1 is extended N-periodic, that is,
xk = xk+N for all k. The FT of this series will be denoted X(k), it will also have N
samples. The forward transform will be defined as

(6)
------------> 2.6

The inverse transform will be defined as

------------> 2.7

Of course although the functions here are described as complex series, real valued
series can be represented by setting the imaginary part to 0. In general, the transform
into the frequency domain will be a complex valued function, that is, with magnitude
and phase.

------------> 2.8
------------> 2.9

The following diagrams show the relationship between the series index and the
frequency domain sample index. Note the functions here are only diagrammatic, in
general they are both complex valued series.

Figure (2.1)

(7)
For example if the series represents a time sequence of length T then the following
illustrates the values in the frequency domain.

Figure (2.2)

Notes

The first sample X(0) of the transformed series is the DC component, more
commonly known as the average of the input series.

The DFT of a real series, ie: imaginary part of x(k) = 0, results in a symmetric series
about the SyQuest frequency. The negative frequency samples are also the inverse of
the positive frequency samples.

The highest positive (or negative) frequency sample is called the SyQuest frequency.
This is the highest frequency component that should exist in the input series for the
DFT to yield "uncorrupted" results. More specifically if there are no frequencies
above Nyquist the original signal can be exactly reconstructed from the samples.

The relationship between the harmonics returns by the DFT and the periodic
component in the time domain is illustrated in figure(2.3).

(8)
Figure (2.3)

2.4 Discrete Fourier Transform

2.4.1 What is the Discrete Fourier Transform?

The general idea is that the image (f(x,y) of size M x N) will be represented in the
frequency domain (F(u,v)). The equation for the two-dimensional discrete Fourier
transform (DFT) is:

(9)
------------> 2.10

The concept behind the Fourier transform is that any waveform that can be
constructed using a sum of sine and cosine waves of different frequencies. The
exponential in the above formula can be expanded into sines and cosines with the
variables u and v determining these frequencies.[4]

The inverse of the above discrete Fourier transform is given by the following
equation:

------------> 2.11

Thus, if we have F(u,v), we can obtain the corresponding image (f(x,y)) using the
inverse, discrete Fourier transform.

Things to note about the discrete Fourier transform are the following:

the value of the transform at the origin of the frequency domain, at F(0,0), is called
the DC component F(0,0) is equal to MN times the average value of f(x,y)

the values of the Fourier transform are complex, meaning they have real and
imaginary parts.

1- The imaginary parts are represented by i, which is the square root of -1. we visually
analyze a Fourier transform by computing a Fourier spectrum (the magnitude of
F(u,v)) and display it as an image. the Fourier spectrum is symmetric about the origin.
The fast Fourier transform (FFT) is a fast algorithm for computing the discrete
Fourier transform.[4][5][6]

(10)
2.5 Compute DFT using MATLAB
MATLAB has three functions to compute the DFT:
 fft -for one dimension (useful for audio)
 fft2 -for two dimensions (useful for images)
 fftn -for n dimensions

MATLAB has three functions that compute the inverse DFT: ifft , ifft2 , ifftn
2.6 How to Display the Fourier Spectrum
The following table is meant to describe the various steps behind displaying the
Fourier Spectrum.
Description MATLAB code

Create an image with a white rectangle f=zeros(30,30);


and black background f(5:24,13:17)=1;
imshow(f,'InitialMagnification','fit')

Image Produced

Table (2.1)

(11)
Description MATLAB code

Calculate the DFT. Notice how there are


real and imaginary parts to F. You must F=fft2(f);
F2=abs(F);
use abs to compute the magnitude
figure,
(square root of the sum of the squares of imshow(F2,[],'InitialMagnification','fit')
the real and imaginary parts).

Image Produced

Table (2.2)

Description MATLAB code

To create a finer sampling of the


F=fft2(f, 256,256);
Fourier transform, you can add
F2=abs(F);
zero padding to f when figure, imshow(F2, [])
computing its DFT

Image Produced

Table (2.3)

(12)
Description MATLAB code

The zero-frequency coefficient is


displayed in the upper left hand F2=fftshift(F);
corner. To display it in the center, F2=abs(F2);
you can use the function figure,imshow(F2,[])

fftshift.

Image Produced

Table (2.4)

Description MATLAB code

To brighten the display, you F2=log(1+F2);


can use a log function figure,imshow(F2,[])

Image Produced

Table (2.5)

(13)
To get the results shown in the last image of the table, you can also combine
MATLAB calls as fallows:

f=zeros(30,30);

f(5:24,13:17)=1;

F=fft2(f, 256,256);

F2=fftshift(F);

figure, imshow(log(1+abs(F2)),[])

Notice in these calls to imshow, the second argument is empty square brackets. This
maps the minimum value in the image to black and the maximum value in the image
to white.[8][9]

2.7 How does the Discrete Fourier Transform relate to Spatial Domain
Filtering?

The following convolution theorem shows an interesting relationship between the


spatial domain and frequency domain:

------------> 2.12

and, conversely,

------------> 2.13

the symbol "*" indicates convolution of the two functions. The important thing to
extract out of this is that the multiplication of two Fourier transforms corresponds to
the convolution of the associated functions in the spatial domain.

(14)
2.8 DFT and FFT algorithm

While the DFT transform above can be applied to any complex valued series, in
practice for large series it can take considerable time to compute, the time taken being
proportional to the square of the number on points in the series. A much faster
algorithm has been developed by Cooley and Tukey around 1965 called the FFT (Fast
Fourier Transform).[4] The only requirement of the most popular implementation of
this algorithm (Radix-2 Cooley-Tukey) is that the number of points in the series be a
power of 2. The computing time for the radix-2 FFT is proportional to

So for example a transform on 1024 points using the DFT takes about 100 times
longer than using the FFT, a significant speed increase. Note that in reality comparing
speeds of various FFT routines is problematic, many of the reported timings have
more to do with specific coding methods and their relationship to the hardware and
operating system.

The Fourier transform is

1 - linear, that is

a f(t) + b g(t) ---> a F(f) + b G(f)

a xk + b yk ---> a Xk + b Yk

2 - Scaling relationship

f(t / a) ---> a F(a f)

f(a t) ---> F(f / a) / a

(15)
3- Shifting

f(t + a) ---> F(f) e-j 2 pi a f

Applying the DFT twice results in a scaled, time reversed version of the original
series.

The transform of a constant function is a DC value only.

Figure (2.4)

The transform of a delta function is a constant

Figure (2.5)

The transform of an infinite train of delta functions spaced by T is an infinite train of


delta functions spaced by 1/T.

Figure (2.6)

(16)
The transform of a cos function is a positive delta at the appropriate positive and
negative frequency.

Figure (2.7)

The transform of a sin function is a negative complex delta function at the appropriate
positive frequency and a negative complex delta at the appropriate negative
frequency.

Figure (2.8)

The transform of a square pulse is a sin function

Figure (2.9)

More precisely, if f(t) = 1 for |t| < 0.5, and f(t) = 0otherwise then

F(f) = sin(pi f) / (pif)

(17)
Convolution

 f(t) x g(t) ---> F(f) G(f)


 F(f) x G(f) ---> f(t) g(t)
 xk x yk ---> N Xk Yk
 xk yk ---> (1/N) Xk x Yk

Multiplication in one domain is equivalent to convolution in the other domain and


visa versa. For example the transform of a truncated sin function are two delta
functions convolved with a sin function, a truncated sin function is a sin function
multiplied by a square pulse.

The transform of a triangular pulse is a sin function. This can be derived from first
principles but is more easily derived by describing the triangular pulse as the
convolution of two square pulses and using the convolution-multiplication
relationship of the Fourier Transform.[4][5][6]

2.9 Sampling theorem

The sampling theorem (often called "Shannons Sampling Theorem") states that a
continuous signal must be discretely sampled at least twice the frequency of the
highest frequency in the signal.

More precisely, a continuous function f(t) is completely defined by samples every 1/fs
(fs is the sample frequency) if the frequency spectrum F(f) is zero for f > fs/2. fs/2 is
called the SyQuest frequency and places the limit on the minimum sampling
frequency when digitizing a continuous signal.

If x(k) are the samples of f(t) every 1/fs then f(t) can be exactly reconstructed from
these samples, if the sampling theorem has been satisfied, by

(18)
------------> 2.14

where

------------> 2.15

Normally the signal to be digitized would be appropriately filtered before sampling to


remove higher frequency components. If the sampling frequency is not high enough
the high frequency components will wrap around and appear in other locations in the
discrete spectrum, thus corrupting it.

The key features and consequences of sampling a continuous signal can be shown
graphically as follows. [5]

Consider a continuous signal in the time and frequency domain.

Figure (2.10)

(19)
Sample this signal with a sampling frequency fs, time between samples is 1/fs. This is
equivalent to convolving in the frequency domain by delta function train with a
spacing of fs.

Figure (2.11)

If the sampling frequency is too low the frequency spectrum overlaps, and become
corrupted.

Figure (2.12)

Another way to look at this is to consider a sine function sampled twice per period
(Nyquist rate). There are other sinusoid functions of higher frequencies that would
give exactly the same samples and thus can't be distinguished from the frequency of
the original sinusoid.

2.10 Two Dimensional (2D) FFT

The following briefly describes how to perform 2 dimensional Fourier transforms.


Source code is given at the end and an example is presented where a simple low pass

(20)
filtering is applied to an image. Filtering in the spatial frequency domain is
advantageous for the same reasons as filtering in the frequency domain is used in time
series analysis, the filtering is easier to apply and can be significantly faster.

It is assumed the reader is familiar with 1 dimensional Fourier transforms as well as


the key time/frequency transform pairs.

------------> 2.16-a

------------> 2.16-b

In the most general situation a 2 dimensional transform takes a complex array. The
most common application is for image processing where each value in the array
represents to a pixel, therefore the real value is the pixel value and the imaginary
value is 0.

2 dimensional Fourier transforms simply involve a number of 1 dimensional Fourier


transforms. More precisely, a 2 dimensional transform is achieved by first
transforming each row, replacing each row with its transform and then transforming
each column, replacing each column with its transform. Thus a 2D transform of a 1K
by 1K image requires 2K 1D transforms. This follows directly from the definition of
the Fourier transform of a continuous variable or the discrete Fourier transform of a
discrete system.

The transform pairs that are commonly derived in 1 dimension can also be derived for
the 2 dimensional situation. The 2 dimensional pairs can often be derived simply by

(21)
considering the procedure of applying transforms to the rows and then the columns of
the 2 dimensional array.

Figure (2.13)

Delta function transforms to a 2D DC plane

Figure (2.14)

Line of delta functions transforms to a line of delta functions

<--FFT-->

Square pulse 2D sin function

Figure (2.15)

(22)
Note

The above example has had the quadrants reorganized so as to place DC (freq = 0) in
the center of the image. The default organization of the quadrants from most FFT
routines is as below

Figure (2.16)

(23)
The following example uses the image
shown on the right.

Figure (2.17)

In order to perform FFT (Fast Fourier


Transform) instead of the much slower
DFT (Discrete Fourier Transfer) the
image must be transformed so that the
width and height are an integer power
of 2. This can be achieved in one of
two ways, scale the image up to the
nearest integer power of 2 or zero pad
to the nearest integer power of 2. The
second option was chosen here to
facilitate comparisons with the
original. The resulting image is 256 x
256 pixels.

Figure (2.18)

(24)
The magnitude of the 2 dimension FFT
(spatial frequency domain) is

Figure (2.19)

Image processing can now be performed (for example filtering) and the image
converted back to the spatial domain. For example low pass filtering involves
reducing the high frequency components (those radially distant from the center of the
above image). Two examples using different cut-off frequencies are illustrated below

Low pass filter with a low

corner frequency Low pass filter with a higher corner frequency

Figure (2.20)

(25)
2.11 Frequency Domain Processing

 Basic Steps in DFT Filtering

The following summarize the basic steps in DFT Filtering

1. Lowpass and Highpass Frequency Domain Filters

Based on the property that multiplying the FFT of two functions from the spatial
domain produces the convolution of those functions, you can use Fourier transforms
as a fast convolution on large images. As a note, on small images, it is faster to work
in the spatial domain.However, you can also create filters directly in the frequency
domain. There are two commonly discussed filters in the frequency domain:

 Lowpass filters, sometimes known as smoothing filters


 Highpass filters, sometimes known as sharpening filters

2.11.1 Lowpass Frequency Domain Filters

Lowpass filters: create a blurred (or smoothed) image

attenuate the high frequencies and leave the low frequencies of the Fourier transform
relatively unchanged

Three main lowpass filters are discussed these filters are:

ideal lowpass filter (ILPF)

Butterworth lowpass filter (BLPF)

Gaussian lowpass filter (GLPF)

(26)
The corresponding formulas and visual representations of these filters are shown in
the table below. In the formulae, D0 is a specified nonnegative number. D(u,v) is the
distance from point (u,v) to the center of the filter.
Lowpass
Formula Mesh Image
Filter
Ideal
Butterworth
Gaussian

Table (2.6)

(27)
The following is the result of applying a Gaussian LowPass filter on an image.
Fourier Spectrum of Image with Gaussian
Original Image
Image LowPass filter

Table (2.7)

The above images were created using two M-files (lpfilter.m and dftuv.m) and the
following MATLAB calls:[8][9]

footBall=imread('football.jpg');

footBall=footBall(:,:,1); % Grab only the Red component to fake gray scaling

imshow(footBall)

PQ = paddedsize(size(footBall));

D0 = 0.05*PQ(1);

H = lpfilter('gaussian', PQ(1), PQ(2), D0); % Calculate the LPF

F=fft2(double(footBall),size(H,1),size(H,2)); % Calculate the discrete Fourier


transform of the image

(28)
LPF_football=real(ifft2(H.*F)); % multiply the Fourier spectrum by the LPF and
apply the inverse, discrete Fourier transform

LPF_football=LPF_football(1:size(footBall,1), 1:size(footBall,2)); % Resize the


image to undo padding

figure, imshow(LPF_football, [])

% Display the Fourier Spectrum

Fc=fftshift(F); % move the origin of the transform to the center of the frequency
rectangle S2=log(1+abs(Fc)); % use abs to compute the magnitude (handling
imaginary) and use log to brighten display

figure, imshow(S2,[])

2.11.2 Highpass Frequency Domain Filters

Highpass filters:

sharpen (or shows the edges of) an image

attenuate the low frequencies and leave the high frequencies of the Fourier transform
relatively unchanged

The highpass filter (Hhp ) is often represented by its relationship to the lowpass filter
(Hlp):

Because highpass filters can be created in relationship to lowpass filters, the following
table shows the three corresponding highpass filters by their visual representations:

(29)
Highpass
Mesh Image
Filter
Ideal
Butterworth
Gaussian

Table (2.8)

(30)
The following is the result of applying a Gaussian HighPass filter on an image.
Fourier Spectrum of Image with Gaussian
Original Image
Image HighPass filter

Table (2.9)

The above images were created using three M-files (lpfilter.m, dftuv.m, and
hpfilter.m) and the following MATLAB calls
footBall=imread('football.jpg');
footBall=footBall(:,:,1); % Grab only the Red component to fake gray scaling
imshow(footBall)
PQ = paddedsize(size(footBall));
D0 = 0.05*PQ(1);
H = hpfilter('gaussian', PQ(1), PQ(2), D0); % Calculate the HPF
F=fft2(double(footBall),size(H,1),size(H,2)); % Calculate the discrete Fourier
transform of the image
HPF_football=real(ifft2(H.*F)); % multiply the Fourier spectrum by the LPF and
apply the inverse, discrete Fourier transform
HPF_football=LPF_football(1:size(footBall,1), 1:size(footBall,2)); % Resize the
image to undo padding

(31)
figure, imshow(HPF_football, [])
% Display the Fourier Spectrum
Fc=fftshift(F); % move the origin of the transform to the center of the frequency
rectangle
S2=log(1+abs(Fc)); % use abs to compute the magnitude (handling imaginary) and
use log to brighten display
figure, imshow(S2,[]) [8][9]

(32)

You might also like