Image Process
Image Process
Image Process
(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.
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.
For a continuous function of one variable f(t), the Fourier Transform F(f) will be
defined as: --------------> 2.1
------------> 2.2
------------> 2.3
------------> 2.4
------------> 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
------------> 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)
(9)
2.4 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:
------------> 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.
(10)
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]
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 and f=zeros(30,30);
black background f(5:24,13:17)=1;
imshow(f,'InitialMagnification','fit')
(11)
Image Produced
Table (2.1)
Image Produced
Table (2.2)
(12)
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 computing
figure, imshow(F2, [])
its DFT
Image Produced
Table (2.3)
Description MATLAB code
The zero-frequency coefficient is
F2=fftshift(F);
displayed in the upper left hand
F2=abs(F2);
corner. To display it in the center,
figure,imshow(F2,[])
you can use the function fftshift.
Image Produced
Table (2.4)
(13)
Image Produced
Table (2.5)
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]
(14)
2.7 How does the Discrete Fourier Transform relate to Spatial Domain
Filtering?
------------> 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.
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.
(15)
The Fourier transform is
1 - linear, that is
a xk + b yk ---> a Xk + b Yk
2 - Scaling relationship
3- Shifting
Applying the DFT twice results in a scaled, time reversed version of the original
series.
Figure (2.4)
(16)
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)
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)
(17)
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
Convolution
xk x yk ---> N Xk Yk
xk yk ---> (1/N) Xk x Yk
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]
(18)
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
------------> 2.14
where
------------> 2.15
The key features and consequences of sampling a continuous signal can be shown
graphically as follows. [5]
(19)
Figure (2.10)
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.
(20)
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.16-a
------------> 2.16-b
(21)
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.
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
considering the procedure of applying transforms to the rows and then the columns of
the 2 dimensional array.
Figure (2.13)
(22)
Figure (2.14)
Line of delta functions transforms to a line of delta functions
<--FFT-->
Figure (2.15)
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
(23)
Figure (2.16)
Figure (2.17)
(24)
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)
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
(25)
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
Figure (2.20)
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:
attenuate the high frequencies and leave the low frequencies of the Fourier transform
relatively unchanged
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
(27)
Butterwo
rth
Gaussian
Table (2.6)
(28)
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');
imshow(footBall)
PQ = paddedsize(size(footBall));
D0 = 0.05*PQ(1);
(29)
figure, imshow(LPF_football, [])
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,[])
Highpass filters:
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:
Highpass
Mesh Image
Filter
(30)
Ideal
Butterworth
Gaussian
Table (2.8)
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
figure, imshow(HPF_football, [])
(32)
% 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]
(33)