Mata kuliah Digital Image Processing Image Enhancement in the Frequency Domain
Pertemuan ke-5 Dr. Hary Budiarto Pasca Sarjana STMIK Eresha
Frequency Domain Methods Spatial Domain
Frequency Domain
Basics of Enhancement in the Frequency Domain
Example for Frequency Domain Method
Filter Function Original signal
Low-pass filtered
High-pass filtered
Band-pass filtered Band-stop filtered
Introduction to the Fourier Transform and the Frequency Domain • The one-dimensional Fourier transform and its inverse – Fourier transform (continuous case)
F (u) f ( x)e j 2uxdx where j 1
– Inverse Fourier transform:
e j cos j sin
f ( x) F (u )e j 2uxdu
• The two-dimensional Fourier transform and its inverse – Fourier transform (continuous case)
F (u, v) f ( x, y)e j 2 (uxvy ) dxdy – Inverse Fourier transform: f ( x, y)
F (u, v)e j 2 (uxvy ) dudv
Introduction to the Fourier Transform and the Frequency Domain • The one-dimensional Fourier transform and its inverse – Fourier transform (discrete case) DTC 1 F (u ) M
M 1
f ( x )e
j 2ux / M
for u 0,1,2,..., M 1
x 0
– Inverse Fourier transform: M 1
f ( x) F (u )e j 2ux/ M u 0
for x 0,1,2,..., M 1
Introduction to the Fourier Transform and the Frequency Domain • Since e j cos j sin and the fact cos( ) cos then discrete Fourier transform can be redefined 1 F (u ) M
M 1
f ( x)[cos 2ux / M j sin 2ux / M ] x 0
for u 0,1,2,..., M 1
– Frequency (time) domain: the domain (values of u) over which the values of F(u) range; because u determines the frequency of the components of the transform. – Frequency (time) component: each of the M terms of F(u).
Introduction to the Fourier Transform and the Frequency Domain • F(u) can be expressed in polar coordinates: F (u ) F (u ) e j (u )
where F (u ) R (u ) I (u ) 2
2
1 2
(magnitude or spectrum)
I (u ) (u ) tan (phase angle or phase spectrum) R(u ) 1
– R(u): the real part of F(u) – I(u): the imaginary part of F(u)
• Power spectrum: P(u) F (u) R 2 (u) I 2 (u) 2
The One-Dimensional Fourier Transform Example
Program Matlab untuk Transformasi Fourier Langkah2 untuk transformasi Fourier 1 dan 2 Dimensi : – Transformasi Fourier 2 dimensi : F = fft(f); – Transformasi Fourier 2 dimensi : F = fft2(f, P, Q); • P, Q adalah ukuran matriks, misalkan M x N ukuran dari gambar yg akan diinputkan maka f adalah pusat dari ukuran matriks PxQ. – Gambar signalnya dapat ditunjukan dengan : imshow(f) – Fungsi absolut untuk fungsi f : abs(f) • Mengembalikan nilai bilangan kompleks untuk f – Memindahkan signal fourier ke tengah2 periode : fftshift(F) – Melihat nilai Real atau imaginary dengan fungsi : real(f); imag(f);
Contoh Transformasi Fourier 1 Dimensi • Gambarkan sinyal untuk transformasi Fourier 1 dimensi (spectrum dan phase angle response). – – – – – – – – – –
M = 1000; f = zeros(1, M); l = 20; f(M/2-l:M/2+l) = 1; F = fft(f); Fc = fftshift(F); rFc = real(Fc); iFc = imag(Fc); Subplot(2,1,1),plot(abs(Fc)); Subplot(2,1,2),plot(atan(iFc./rFc));
Contoh Transformasi Fourier 2 Dimensi • Program untuk Transformasi fourier 2 Dimensi – – – – – – – – – – – –
f = ones(10,20); F = fft2(f, 500,500); f1 = zeros(500,500); f1(240:260,230:270) = 1; subplot(2,2,1);imshow(f1,[]); S = abs(F); subplot(2,2,2); imshow(S,[]); Fc = fftshift(F); S1 = abs(Fc); subplot(2,2,3); imshow(S1,[]); S2 = log(1+S1); subplot(2,2,4);imshow(S2,[]);
• Transformasi Fourier untuk citra : – i = imread(‘image-2.jpg’); – f=i(:,:,1); – subplot(1,2,1), imshow(f); – f = double(f); – F = fft2(f); – Fc = fftshift(F); – S = log(1+abs(Fc)); – Subplot(1,2,2),imshow(S,[]);
Sharpening Frequency Domain Filter Filter Penajaman pada domain Frekuensi
H hp (u, v) H lp (u, v) Ideal highpass filter
0 H (u, v) 1
if D(u, v) D0 if D(u, v) D0
Butterworth highpass filter H (u, v)
1 2n 1 D0 / D(u, v)
Gaussian highpass filter
H (u, v) 1 e
D 2 ( u ,v ) / 2 D02
Highpass Filters Spatial Representations
Ideal Highpass Filters
0 H (u, v) 1
if D(u, v) D0 if D(u, v) D0
Butterworth Highpass Filters
1 H (u, v) 2n 1 D0 / D(u, v)
Gaussian Highpass Filters
H (u, v) 1 e
D 2 ( u ,v ) / 2 D02
Ideal Lowpass Filters (ILPFs) • The transfer function of an ideal lowpass filter 1 if D(u, v) D0 H (u, v) 0 if D(u, v) D0 where D(u,v) : the distance from point (u,v) to the center of ther frequency rectangle 1 D(u, v) (u M / 2) 2 (v N / 2) 2 2
Butterworth Lowpass Filters (BLPFs) With order n
1 H (u, v) 2n 1 D(u, v) / D0
Butterworth Lowpass Filters (BLPFs)
n=2 D0=5,15,30,80,and 230
Gaussian Lowpass Filters (FLPFs)
H (u, v) e
D 2 ( u ,v ) / 2 D02
Gaussian Lowpass Filters (FLPFs)
D0=5,15,30,80,and 230
Program Matlab Gaussian Lowpass Filters i = imread('image-2.jpg'); f=i(:,:,1); [m,n] = size(f); % cek nilai ukuran gambar if(mod(m,2) == 0); cM = floor(m/2) + 0.5; else; cM = floor(m/2) + 1; end; if(mod(n,2) == 0); cN = floor(n/2) + 0.5; else; cN = floor(n/2) + 1; end
F = fftshift(fft2(double(f))); dnol = 10; H= zeros(m,n); for i = 1:n; for j = 1:n; dis = (i - cM)^2 + (j - cN)^2; H(i,j) = exp(-dis/2/dnol^2); end; end;
D0=10
G = H.*F; g = abs(ifft2(G)); subplot(1,2,1), imshow(f); subplot(1,2,2),imshow(g,[]);
D0=20
D0=45