Image Enhancement in Frequency Domain. Jean BaptisleJoseph Fourier French Mathematician ( )

Image Enhancement in Frequency Domain Jean Baptisle Joseph Fourier Jean Baptisle Joseph Fourier French Mathematician (1768 - 1830) Image Enhancemen...
Author: Benjamin Hunt
2 downloads 1 Views 2MB Size
Image Enhancement in Frequency Domain Jean Baptisle Joseph Fourier

Jean Baptisle Joseph Fourier French Mathematician (1768 - 1830)

Image Enhancement in Frequency Domain Fourier Series Periodic functions can be represented as a weighted sum of sines and/or cosines of different frequencies

Image Enhancement in Frequency Domain Fourier Transform Functions that are not periodic (but whose area under the curve is finite) can be represented as the integral of sines and/or cosines multiplied by a weighing function.

Image Enhancement in Frequency Domain Fourier Transform 1-D (Continuous case) Fourier Transform: Inverse Fourier Transform:

F (u ) = f ( x) =





f ( x )e − j 2πux dx

−∞ ∞

∫ F ( u )e

−∞

j 2πux

du

Image Enhancement in Frequency Domain 1-D DFT 1-D (Discrete case) Fourier Transform:

1 F (u ) = M

M −1



f ( x )e − j 2πux / M

x =0

u = 0,…,M-1

Inverse Fourier Transform:

f ( x) =

M −1

j 2πux / M F ( u ) e ∑ u =0

x = 0,…,M-1

Image Enhancement in Frequency Domain 1-D DFT F(u) can be written as

F (u ) = R(u ) + jI (u )

or

F (u ) = F (u ) e − jφ ( u )

where

F ( u ) = R ( u ) + I (u ) 2

2

 I (u )  φ (u ) = tan    R (u )  −1

Image Enhancement in Frequency Domain 2-D DFT For an image of size MxN pixels 2-D DFT

1 F (u, v ) = MN

M −1 N −1

− j 2π ( ux / M + vy / N ) f ( x , y ) e ∑∑ x =0 y =0

u = frequency in x direction, u = 0 ,…, M-1 v = frequency in y direction, v = 0 ,…, N-1

2-D IDFT

f ( x, y ) =

M −1 N −1

j 2π ( ux / M + vy / N ) F ( u , v ) e ∑∑ u =0 v =0

x = 0 ,…, M-1 y = 0 ,…, N-1

Image Enhancement in Frequency Domain 2-D DFT F(u,v) can be written as

F (u, v ) = R(u, v ) + jI (u, v ) or F (u, v ) = F (u, v ) e − jφ ( u ,v ) where

F ( u, v ) = R ( u, v ) + I ( u, v ) 2

2

 I (u, v )  φ (u, v ) = tan    R (u, v )  −1

Image Enhancement in Frequency Domain 2-D DFT

Image Enhancement in Frequency Domain 2-D DFT

Image Enhancement in Frequency Domain 2-D DFT

Image Enhancement in Frequency Domain 2-D DFT

Image Enhancement in Frequency Domain Perform 2-D DFT using 1-D DFT

f(x,y)

1-D DFT by row

F(u,y) 1-D DFT by column

F(u,v)

Image Enhancement in Frequency Domain Perform 2-D DFT using 1-D DFT

Alternative method f(x,y) 1-D DFT by column

F(x,v)

1-D DFT by row

F(u,v)

Image Enhancement in Frequency Domain Periodicity of 1-D DFT From DFT:

-N

1 F (u ) = M

0

M −1



f ( x ) e − j 2πux / M

x =0

N

2N

We display only in this range

DFT repeats itself every N points (Period = N) but we usually display it for n = 0 ,…, N-1

Image Enhancement in Frequency Domain Conventional Display for 1-D DFT F (u )

f(x) DFT

N-1

0

N-1

0

Time Domain Signal High frequency area Low frequency area

Image Enhancement in Frequency Domain FFT Shift F (u )

0

F (u )

N-1

High frequency area Low frequency area

-N/2

0

N/2-1

Image Enhancement in Frequency Domain Periodicity of 2-D DFT 2-D DFT:

1 F (u, v ) = MN

M −1 N −1

∑∑

f ( x, y )e − j 2π ( ux / M + vy / N )

f(x,y)

x =0 y = 0

-M

0

For an image of size NxM pixels, its 2-D DFT repeats itself every N points in xdirection and every M points in y-direction.

M

2M -N

0

N

2N

We display only in this range (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Conventional Display for 2-D DFT F(u,v) has low frequency areas at corners of the image while high frequency areas are at the center of the image which is inconvenient to interpret.

High frequency area Low frequency area

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain 2-D FFT Shift

2D FFTSHIFT

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

High frequency area

Low frequency area

Image Enhancement in Frequency Domain 2-D FFT Shift -M

0 Display of 2D DFT After FFT Shift M

2M -N

0

N

Original display of 2D DFT

2N

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Example of 2-D DFT

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Example of 2-D DFT

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Example of 2-D DFT 2D DFT

Original image

2D FFT Shift

Image Enhancement in Frequency Domain Example of 2-D DFT 2D DFT

Original image

2D FFT Shift

Image Enhancement in Frequency Domain 2-D FFT & FFT Shift 2-D FFT Shift is a MATLAB function: Shift the zero frequency of F(u,v) to the center of an image.

>> f = imread(`filename’) >> F = fft2(f); >> S = abs(F); >> imshow(S,[ ]) >> Fs = fftshift(F); >> figure, imshow(abs(Fs), [ ]) >> Slog = log(1+abs(Fs)); >> figure, imshow(Slog,[]) fftshift(fft2(f)) = FT[(-1)x+y f(x,y)]

Image Enhancement in Frequency Domain Basic Concept of Filtering in the Frequency Domain From Fourier Transform Property:

g( x, y) = f ( x, y) ∗ h( x, y) ⇔ F (u, v) ⋅ H (u, v) = G(u, v) We can perform filtering process by using

Multiplication in the frequency domain is easier than convolution in the spatial Domain. (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Filtering in the Frequency Domain with FFT Shift H(u,v) (User defined)

F(u,v)

FFT shift

X

2D FFT

f(x,y)

g(x,y)

2D IFFT

FFT shift

G(u,v)

In this case, F(u,v) and H(u,v) must have the same size and have the zero frequency at the center.

Image Enhancement in Frequency Domain Example of Filtering in the Frequency Domain In this example, we set F(0,0) to zero which means that the zero frequency component is removed.

Note: Zero frequency = average intensity of an image

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain MATLAB Example >> f = imread(`Fig4.04(a).jpg’); >> [M, N] = size(f); >> F = fft2(f); >> Fs = fftshift(F); >> Fs(floor(M/2)+1,floor(N/2)+1) = 0; % Apply notch filter >> Fb = ifftshift(Fs); >> fb = real(ifft2(Fb)); >> I = uint8(fb); >> imshow(I)

Image Enhancement in Frequency Domain Example of Filtering in the Frequency Domain In this example, we set F(0,0) to zero which means that the zero frequency component is removed.

Note: Zero frequency = average intensity of an image

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Example of Filtering in the Frequency Domain Lowpass Filter

Highpass Filter (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Example of Filtering in the Frequency Domain

Result of Sharpening Filter (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Filters

1. Ideal Filter 2. Butterworth Filter 3. Gaussian Filter

Image Enhancement in Frequency Domain Filter Masks and Their Fourier Transforms

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Ideal Lowpass Filter Ideal LPF Filter Transfer function D(u, v ) ≤ D0 1 H ( u, v ) =  D (u, v ) > D0 0 where D(u,v) = Distance from (u,v) to the center of the mask.

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Examples of Ideal Lowpass Filters

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

The smaller D0, the more high frequency components are removed.

Image Enhancement in Frequency Domain Results of Ideal Lowpass Filters

Ringing effect can be obviously seen!

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Ringing Effect 1 H ( u, v ) =  0

D(u, v ) ≤ D0 D (u, v ) > D0 Surface Plot

1 0.8 0.6

Ideal Lowpass Filter with D0 = 5

0.4 0.2 0 20

Abrupt change in the amplitude

20

0

0 -20

-20

Image Enhancement in Frequency Domain Ringing Effect

Surface Plot -3

x 10

15 10

Spatial Response of Ideal Lowpass Filter with D0 = 5

5 0

20

Ripples that cause ringing effect

20

0

0 -20

-20

Image Enhancement in Frequency Domain Ringing Effect

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Transfer function Butterworth Lowpass Filter H ( u, v ) =

1 2N 1 + [D(u, v ) / D0 ]

Where D0 = Cut off frequency, N = filter order.

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Results of Butterworth Lowpass Filters

There is less ringing effect compared to those of ideal lowpass filters! (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Spatial Masks of the Butterworth Lowpass Filters

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Some ripples can be seen.

Image Enhancement in Frequency Domain Transfer Lowpass function Filter Gaussian H ( u, v ) = e Where D0 = spread factor.

− D 2 ( u ,v ) / 2 D0 2

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Note: the Gaussian filter is the only filter that has no ripple and hence no ringing effect.

Image Enhancement in Frequency Domain Gaussian Lowpass Filter H ( u, v ) = e

1

− D 2 ( u ,v ) / 2 D0 2

0.8

Gaussian lowpass filter with D0 = 5

0.6 0.4 0.2

20 20

0

0 -20

-20

Spatial response of the Gaussian lowpass filter with D0 = 5

0.03

0.02

0.01

0 20 20

0

0 -20

Gaussian shape

-20

Image Enhancement in Frequency Domain Results of Gaussian Lowpass Filters

No ringing effect!

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Application of Gaussian Lowpass Filters

Original image

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Better Looking

The GLPF can be used to remove jagged edges and “repair” broken characters.

Image Enhancement in Frequency Domain Application of Gaussian Lowpass Filters Remove wrinkles

Original image

Softer-Looking (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Lowpass Filters

ILPF

BLPF

GLPF

Image Enhancement in Frequency Domain MATLAB Examples >> H = lpfilter(‘ideal’,500,500,50); >> mesh(H(1:10:500,1:10:500)) >> axis([0 50 0 50 0 1]) >> colormap >> grid off, axis off >> H = lpfilter(‘btw’,500,500,50,2); >> surf(H(1:10:500,1:10:500)) >> axis([0 50 0 50 0 1]) >> colormap >> grid off, axis off

Image Enhancement in Frequency Domain MATLAB Example >> f = imread(‘filename’); >> [M, N] = size(f); >> F = fft2(f); >> sig = 10; >> H = lpfilter(‘gaussian’, M, N, sig); >> G = H.*F; >> g = real(ifft2(G)); >> imshow(g, [])

Image Enhancement in Frequency Domain Highpass Filters

Hhp = 1 - Hlp

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Ideal Highpass Filter Ideal HPF Filter Transfer function 0 H ( u, v ) =  1

D (u, v ) ≤ D0 D(u, v ) > D0

where D(u,v) = Distance from (u,v) to the center of the mask.

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Butterworth Highpass Filter Transfer function

1 H ( u, v ) = 2N 1 + [D0 / D (u, v )]

Where D0 = Cut off frequency, N = filter order.

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Gaussian Highpass Filter Transfer function H ( u, v ) = 1 − e

− D 2 ( u ,v ) / 2 D0 2

Where D0 = spread factor.

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Gaussian Highpass Filter H ( u, v ) = 1 − e

1

− D 2 ( u ,v ) / 2 D0 2

0.8

Gaussian highpass filter with D0 = 5

0.6 0.4 0.2 0 60 40 20 10

20

30

40

50

60

3000 2000

Spatial response of the Gaussian highpass filter with D0 = 5

1000 0 60 40 20 10

20

30

40

50

60

Image Enhancement in Frequency Domain Spatial Responses of Highpass Filters

Ripples

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Results of Ideal Highpass Filters

Ringing effect can be obviously seen! (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Results of Butterworth Highpass Filters

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain Results of Gaussian Highpass Filters

(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.

Image Enhancement in Frequency Domain MATLAB Examples >> H = hpfilter(‘gaussian’,500,500,50); >> mesh(H(1:10:500,1:10:500)) >> axis([0 50 0 50 0 1]) >> colormap >> grid off, axis off >> H = hpfilter(‘gaussian’,500,500,50); >> surf(H(1:10:500,1:10:500)) >> axis([0 50 0 50 0 1]) >> colormap >> grid off, axis off

Image Enhancement in Frequency Domain MATLAB Example >> f = imread(‘filename’); >> h = fspecial(‘sobel’) >> H = freqz2(h); >> Hs = ifftshift(H); >> gf = dftfilt(f, Hs); >> imshow(gf,[])

Image Enhancement in Frequency Domain