Professional Documents
Culture Documents
Lecture:
IMAGE PROCESSING
Chương 3:
Biến đổi Fourier
Ngo Ba Viet 1
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Fourier Transform
Giới thiệu
- Fourier Transform (FT): an image in the spatial is transformed to
consider in the frequency domain. One can use the FT in filtering
image or others
- FT of two-dimensional (2D)
- Properties of Discrete Fourier Transform
- Applications
• Extracting feature of image based on frequency
• Filtering noise
• Determining frequencies in an image
2
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Fourier Transform
Biến đổi Fourier rời rạc 1D
4
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
5
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
6
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
M 1 N 1 2 ux 2 vy
Gu, v g x, y e
j j
M
e N
x 0 y 0
7
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
MN u 0 v 0
Với x=0,1,…,M-1 và y=0,1,…,N-1. g(x,y)
8
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Giả sử R(u,v) và I(u,v) biểu diễn các thành phần thực và phần ảo của G(u,v),
phổ biên độ Fourier được định nghĩa::
𝐺(𝑢, 𝑣) = 𝑅2 𝑢, 𝑣 + 𝐼 2 𝑢, 𝑣
Góc pha của của biến đổi được xác định như sau:
𝐼(𝑢, 𝑣)
𝜃(𝑢, 𝑣) = tan−1
𝑅(𝑢, 𝑣)
Phổ công suất được định nghĩa như là bình phương của biên độ:
𝑃 𝑢, 𝑣 = |𝐺(𝑢, 𝑣)|2 = 𝑅2 𝑢, 𝑣 + 𝐼 2 𝑢, 𝑣
Giá trị biến đổi tại gốc của miền tần số (nghĩa là hệ số G(0,0) ) được gọi là
thành phần một chiều DC của biến đổi Fourier. Thuật ngữ này có thể gọi là
thành phần có tần số bằng không.
9
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Ví dụ: Biến đổi Fourier của ảnh kích thước 4x4 sau:
0 0 0 0
0 1 1 0
g ( x, y )
0 1 1 0
0 0 0 0
10
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
0 0 0 0
g(𝑥, 𝑦) = 0 1 1 0
0 1 1 0
0 0 0 0
Biến đổi Fourier của 𝑔 với việc tính toán từng giá trị cụ thể tại từng vị
trí, chẳng hạn như với 𝑢 = 1 và 𝑣 = 0.
1 1 2 2
−𝑗2𝜋 4 −𝑗2𝜋 4 −𝑗2𝜋 4 −𝑗2𝜋 4
G 1,0 = 𝑒 +𝑒 +𝑒 +𝑒
= −𝑗 − 𝑗 − 1 − 1
= −2 − 2𝑗
4 + 𝑗0 −2 − 𝑗2 0 + 𝑗0 −2 + 𝑗2
−2 − 𝑗2 0 + 𝑗2 0 + 𝑗0 2 + 𝑗0
G(u, v) =
0 + 𝑗0 0 + 𝑗0 0 + 𝑗0 0 + 𝑗0
−2 + 𝑗2 2 + 𝑗0 0 + 𝑗0 0 − 𝑗2
11
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Ví dụ 3.1: Biến đổi Fourier không dùng hàm có sẵn trong MATLAB
clear all;clc
a=zeros(4,4);
a(2:3,2:3)=1;
%a =[0 0 0 0; 0 1 1 0; 0 1 1 0; 0 0 0 0]
[M,N]=size(a)
for u=1:M % size(a,1)
for v=1:N% size(a,2)
for x=1:size(a,1)
for y=1:size(a,2)
phi=(2*pi*(u-1)*(x-1)+2*pi*(v-1)*(y-1))/4;
p(x,y)=complex(cos(phi),-sin(phi));
end
end
F(u,v)=sum(sum(p.*a));
end 12
end
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Central shift
𝑀
𝜀 𝑓(𝑥, 𝑦)(−1)(𝑥+𝑦) = 𝐹(𝑢 − , 𝑣 − 𝑁/2)
2
Trong kết quả của biến đổi DFT, gốc tọa độ ở góc trên bên trái của ma
trận tần số.
Trong các ứng dụng, gốc tọa độ này cần được dịch về trung tâm hình
chữ nhật tần số, bằng cách chuyển đổi vị trí các vùng trong kết quả.
13
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
14
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Central shift
Trong trường hợp kích thước ảnh không là số chẵn, ta có thể dịch vòng
điểm ảnh theo hàng, sau đó dịch vòng theo cột để dời gốc tọa độ về
trung tâm.
VD: Thực hiện dời gốc tọa độ về trung tâm cho ảnh DFT A
1 4 7
A 3 9 2
6 5 8
7 1 4
8 6 5
Ah 2 3 9 Ac 7 1 4
8 6 5 2 3 9
Dịch vòng theo hàng 1 đơn vị Dịch vòng theo cột 1 đơn vị 15
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
16
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
F=fft2(f)
This function will return image of FT with the 𝑀 × 𝑁 size, having data
arranged as in Fig. and the axis origin will be the upper left side of image and
the end period is at the frequency rectangular center.
(a) Fourier spectrum with 𝑀 × 𝑁 size and four quad angles of the period;
(b) Fourier spectrum with 𝑀 × 𝑁 size with the center origin of frequency.
This stectrum is obtain by multiplying the function 𝑓(𝑥, 𝑦) and −1 𝑥+𝑦
before using the FT.
17
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Some functions for Fourier transform:
F=fft2(f)
Amplitude spectrum of Fourier transform:
S=abs(F)
The center shift, Fc=fftshift(F)
Fig. (a). Original image; (b) Fourier spectrum with the center at the foue
quad angles; (c) Fourier spectrum shifted with the center at the coordinate
origin; (d) Fourier spectrum represented using log transform
4 −2 − 𝑗2 0 −2 + 𝑗2
−2 − 𝑗2 𝑗2 0 2
G(u, v) =
0 0 0 0
−2 + 𝑗2 2 0 𝑗2
0 0 0 0
0 2j -2 + 2j 2
Gc(u, v) = 0 -2 + 2j 4 2 – 2j
0 2 -2 – 2j 2j
19
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Functions: “fftshift” and “ifftshift” will
Ví dụ 3.2: Perform the FT of image
transfer the angle position into the
and calculate its Fourier spectrum.
original one.
F=ifftshift(Fc)
clear all;
The inverse FT
close all;
f=ifft2(F)
f=imread('TestDFT.tif');
F is the FT, f is image in the spatial
F=fft2(f);
domain. If the input of F is real, f is real.
S=abs(F);
However, in practice, function ifft2 often
Fc=fftshift(F);
has a small complex value, its result
Sc=abs(Fc);
will be complex, so we can use function
S2=log(1+abs(Fc));
to produce real values:
figure;
f=real(ifft2(F))
subplot(2,2,1);imshow(f);
subplot(2,2,2);imshow(S);
subplot(2,2,3);imshow(Sc);
subplot(2,2,4);imshow(S2);
20
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Bài tập:
Tính toán DFT của ảnh sau:
0 0 0 0
0 1 1 0
g ( x, y )
0 1 1 0
0 0 0 0
Hướng dẫn:
Biến đổi Fourier rời rạc của một ảnh hai chiều (2-DFT) g(x, y) có thể
được viết lại theo dạng như sau
G U * g *V T
j 2xu j 2yv
U ( x, u ) e M
; x, u 0 : M 1 V ( y, v) e N
; y, v 0 : N 1
21
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Bài tập:
Đầu tiên, tìm ma trận U:
e 4
j2 00 j2 01 j2 02 j2 03
e 4
e 4
e 4
e 4
U j2 20
e 4 e 4 e 4
e 4 j2 21
e 4
j2 22
e 4 e 4
j2 23
1 1 1 1
1 j 1 j
V
1 1 1 1
1 j 1 j
Suy ra:
1 1 1 1 0 0 0 0 1 1 1 1
1 j 1 j 0 1 1 0 1 j 1 j
G U * g *V * *
1 1 1 1 0 1 1 0 1 1 1 1
1 j 1 j 0 0 0 0 1 j 1 j
23
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Bài tập:
Kết quả biến đổi Fourier của g(x,y):
4 2 j2 0 2 j 2
2 j 2 j2 0 2
G
0 0 0 0
2 2 j 2 0 j2
4 2 2 0 2 2
G
2 2 2 0 2
0 0 0 0
2 2 2 0 2
24
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Bài tập:
Tính toán DFT của ảnh sau:
25
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Exercise
A B
26
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Tạo chương trình con fft2_new.m để tìm biến đổi Fourier của ảnh.
27
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Tạo chương trình con fft2_new.m để tìm biến đổi Fourier của ảnh.
%=================== %===================
% create matrix V %Fourier transform
%V(y,v)=exp(-j*2*pi*y*v/N) G=U*g*V;
% y, v run from 0 to N-1
V=[ ];
for y=0:N-1
for v=0:N-1
V(y+1,v+1)=exp(-
j*2*pi*y*v/N);
end
end
28
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
Tạo chương trình con ifft2_new.m để biến đổi Fourier ngược của ảnh
29
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
30
University of Technology and Education
Faculty of Electrical & Electronic Engineering
Image Transforms
The End
31