Tải bản đầy đủ (.pdf) (70 trang)

lecture chapter 4 frequency domain processing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.17 MB, 70 trang )

Chapter4 Frequency Domain
Processing
Image Enhancement in the
Frequency Domain
Jean Baptiste Joseph Fourier (1768-1830)

had crazy idea (1807):

Any periodic function can be
rewritten as a weighted sum of
sines and cosines of different
frequencies.

Don’t believe it?
– Neither did Lagrange,
Laplace, Poisson and
other big wigs
– Not translated into
English until 1878!

But it’s true!
– called Fourier Series
Introduction to the Fourier Transform

Any function that periodically repeats itself can be expressed as
the sum of sines and/or cosines of different frequencies, each
multiplied by a different coefficient (Fourier series).

Even functions that are not periodic (but whose area under the
curve is finite) can be expressed as the integral of sines and/or
cosines multiplied by a weighting function (Fourier transform).



The advent of digital computation and the “discovery” of fast
Fourier Transform (FFT) algorithm in the late 1950s
revolutionized the field of signal processing, and allowed for the
first time practical processing and meaningful interpretation of
a host of signals of exceptional human and industrial
importance.
Frequency Domain Processing

The frequency
domain refers to
the plane of the two
dimensional
discrete Fourier
transform of an
image.

The purpose of the
Fourier transform
is to represent a
signal as a linear
combination of
sinusoidal signals of
various frequencies.
Frequency Domain Processing
=
+
example : g(t) = sin(2pi f t) + (1/3)sin(2pi (3f) t)
1D Fourier transform and its inverse
1

2 /
0
( ) ( ) for 0,1, 2, , 1
M
j ux M
x
F u f x e u M
π


=
= = −

1
2 /
0
1
( ) ( ) for 0,1, 2, , 1
M
j ux M
u
f x F u e x M
M
π

=
= = −

 Fourier transform (DFT)


Inverse Fourier transform (IDFT)
2D Fourier transform and its inverse
1 1
2 ( / / )
0 0
( , ) ( , )
for 0,1, 2, , 1, 0,1, 2, , 1
M N
j ux M vy N
x y
F u v f x y e
u M v N
π
− −
− +
= =
=
= − = −
∑ ∑
1 1
2 ( / / )
0 0
1
( , ) ( , )
for 0,1, 2, , 1, 0,1, 2, , 1
M N
j ux M vy N
u v
f x y F u v e
MN

x M y N
π
− −
+
= =
=
= − = −
∑∑
 Fourier transform (DFT)

Inverse Fourier transform (IDFT)
Discrete Fourier Transform
The Fourier transform of a discrete function f(x), x=0,1,2,…,M-1 is given by
(Discrete Fourier transform, DFT)
inverse DFT
The multiplier 1/M in front of the Fourier transform
sometimes is placed in front of the inverse instead
Or, both equations are multiplied by
1, ,2,1,0 )(
1
)(
1
0
/2
−==


=

Muforexf

M
uF
M
x
Muxj
π
1, ,2,1,0 )()(
1
0
/2
−==


=
MxforeuFxf
M
u
Muxj
π
M/1
Discrete Fourier Transform
Euler’s formula
DFT is represented as
Each term of the Fourier transform is composed of the sum of all values
fo the function f(x). The values of f(x) are multiplied by sines and cosines
of various frequencies
The domain (values of u) of F(u) is appropriately called frequency
domain because u determines the frequency of the components of the
transform
θθ

θ
sincos je
j
+=
1, ,2,1,0
]/2sin/2)[cos(
1
)(
1
0
−=
−=


=
Mufor
MuxjMuxxf
M
uF
M
x
ππ
Discrete Fourier Transform
The Fourier transform may be viewed as a “mathematical prism” that separates
a function into various components based on frequency content
In the analysis of complex numbers, it is convinient to express F(u) in polar
coordinates
where
)(
|)(|)(

uj
euFuF
φ
=
1/2
2 2
1
2
2 2
( ) ( ) ( ) ;
( )
( ) tan :
( )
( ) ( ) ( ) ( ) :
F u R u I u magnitude, spectrum
I u
u phase angle, phase spectrum
R u
P u F u R u I u power spectrum
ϕ

 
= +
 
 
=
 
 
= = +
2D DFT and Inverse DFT (IDFT)

Nj
N
eW
/2
π

=
M, N: image size
x, y: image pixel position
u, v: spatial frequency
f(x, y) F(u, v)
Filtering in frequency domain
 Low-pass filters: preserve low frequencies, useful
for noise suppression
 High-pass filters: preserves high frequencies,
useful for edge detection
Filtering in frequency domain
Original signal
Low-pass filtered
High-pass filtered
Computing and visualizing DFT
Computing and visualizing DFT
Clc; clear all;
I=imread('F1.bmp'); % tao anh F1 trong Paint
F=fft2(I);
S=abs(F);
Fc=fftshift(F);
S1=abs(Fc);
subplot(2, 2, 1), imshow(I); title('original Image',…
'FontSize',14)

subplot(2, 2, 2);imshow(S);title('Fourier spectrum',…
'FontSize',14)
subplot(2, 2, [3 4]); imshow(S1);title('Centered spectrum', …
'FontSize',14)
Computing and visualizing DFT
Computing and visualizing DFT
clc
clear all;
I=imread('F1.bmp');
F=fft2(I);
F0=ifft2(F);
subplot(2, 2, 1), imshow(I); title('original Image', 'FontSize',14)
subplot(2, 2, 2);imshow(F);title('Fourier tranform fft2',…
'FontSize',14)
subplot(2, 2, [3 4]); imshow(F0);title('Centered spectrum:
ifft2',… 'FontSize',14)
Filtering in the frequency domain
The convolution theorem:

Linear spatial convolution is by convolving f(x,y) and
h(x,y). The same result is obtained in the frequency domain
by multiplying F(u,v) and H(u,v).

The basic idea in frequency domain is to select a filter
transfer function that modifies F(u,v) in a specified manner.

A filter is called low pass filter if it attenuates the high
frequency components to F(u,v) while leaving the low
frequencies relatively unchanged.
),(),(),(),( vuFvuHyxhyxf



clear all;
f=zeros(5);
f(3,3)=1;
w=[1 2 3; 4 5 6 ; 7 8 9];
[a b]=size(w);[c d]=size(f);
P=(a+c)-1;Q=(b+d)-1;
g=imfilter(f,w,'conv',0,'full')
F=fft2(f, P, Q );
W=fft2(w, P, Q);
G=W.*F;
G=real(ifft2(G))
),(),(),(),( vuFvuHyxhyxf


Filtering in the frequency domain
g =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 2 3 0 0
0 0 4 5 6 0 0
0 0 7 8 9 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
G =
0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 1.0000 2.0000 3.0000 0.0000 0.0000
0.0000 0.0000 4.0000 5.0000 6.0000 -0.0000 0.0000

0.0000 0.0000 7.0000 8.0000 9.0000 0 0.0000
0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Fourier Transform
Fourier Transform

The Fourier Transform is of fundamental importance
to image processing.

its efficiency allows us to perform other tasks more
quickly.

The Fourier Transform provides, among other
things, a powerful alternative to linear spatial
filtering;

it is more efficient to use the Fourier transform than
a spatial filter for a large filter.

The Fourier Transform also allows us to isolate and
process particular image frequencies and so perform
low-pass and high-pass filtering with a great degree
of precision.
Paddedsize function
function PQ = paddedsize(AB, CD, PARAM)
% PQ(1) = PQ(2) = 2^nextpow2(2*m), where m is MAX([AB CD]).
if nargin == 1
PQ = 2*AB; elseif nargin == 2&~ischar(CD)
PQ = AB + CD - 1; PQ = 2 * ceil(PQ / 2);
elseif nargin == 2

m = max(AB); % Maximum dimension.
% Find power-of-2 at least twice m.
P = 2^nextpow2(2*m);
PQ = [P, P];
elseif nargin == 3
m = max([AB CD]); %Maximum dimension.
P = 2^nextpow2(2*m);
PQ = [P, P];
else
error('Wrong number of inputs.')
end
Paddedsize function
clear all;
clc
f=ones(5);
h=fspecial('sobel');
AB=size(f,1)
CD=size(h,1)
Q=paddedsize(AB, CD, 'PWR2')
Paddedsize function
Paddedsize function
clear all, clc; sigma=10;
f=zeros(240); f(1:120, :)=1;
[M N]=size(f);
F1=fft2(f, M, N);
H1=lpfilter('gaussian', M, N, sigma);
G1=H1.*F1;
g1=real(ifft2(G1));subplot(2, 2, 1); imshow(f)
subplot(2, 2, 2); imshow(g1)
%============ with padding

PQ=paddedsize(size(f), 'PWR2');
F=fft2(f, PQ(1), PQ(2));
H=lpfilter('gaussian', PQ(1), PQ(2), sigma);
G=H.*F;
g=real(ifft2(G));
subplot(2, 2, 3)
imshow(g(1:size(f),1:size(f)))
subplot(2, 2, 4)
imshow(g)

×