0% found this document useful (0 votes)
65 views

Lecture03 FT 2D

- The 2-D convolution theorem states that convolution in the spatial domain is equivalent to multiplication in the frequency domain. - An image can be represented as a sum of point sources (Dirac delta functions), with the point spread function describing how a point source is spread out after a linear operation. - Convolution of an image with a point spread function is equivalent to applying that linear operation to the image.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Lecture03 FT 2D

- The 2-D convolution theorem states that convolution in the spatial domain is equivalent to multiplication in the frequency domain. - An image can be represented as a sum of point sources (Dirac delta functions), with the point spread function describing how a point source is spread out after a linear operation. - Convolution of an image with a point spread function is equivalent to applying that linear operation to the image.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

2-D Fourier Transform

• 2-D Continues Fourier Transform


• 2-D Discrete Fourier Transform
• 2-D Fourier Properties
• 2-D Convolution Theorem
• MATLAB 2-D FFT Practice
The Convolution Theorem
 Convolution in one domain is multiplication in the other and vice versa

g=f*h g=fh

implies implies

G=FH G=F*H

and likewise
Convolution Theorem - 1-D Example 1

1 if x  0
Dirac function  ( x)  
0 otherwise

Proof : Consider any function f(x)


f ( x) *  ( x)  f ( x)

* =
Convolution Theorem - 1-D Example 2

f(x) f(x) h(x)

* =
1
x
-0.5 0.5 -0.5 0.5 -1

FFT FFT IFFT

F() F() H()


. =


f x   g x   F F  f x F g x 
~ 1 ~ ~

Convolution Theorem - 1-D Example 3

Constant Function g ( x)  c

Proof : Consider any function g(x)

f x  g x   cf (x)

F u   Gu   cF (u)

 =
~
F[c]  c (u)
Convolution Theorem – 1-D Example 4

f (x)* g (x)
f(x)
* g(x)
=
1 1 1
0.8 0.8 0.8
0.6 0.6 0.6
0.4 0.4 0.4
0.2 0.2 0.2
00 50 100 00 50 100 00 50 100

F(u) . G(u) = F(u)G(u) F-1[F(u) G(u)]


10 10 10 1
8 8 8 0.8
6 6 6 0.6
4 4 4 0.4
2 2 2 0.2
00 50 100 00 50 100 00 50 100 00 50 100
Qualitative Properties

 The spectrum of a functions tells us the


relative amounts of high and low frequencies
– Sharp edges give high frequencies
– Smooth variations give low frequencies
 A function is bandlimited if its spectrum has no
frequencies above a maximum limit
– sin, cos are band limited
– Box, Gaussian, etc are not
Functions to Images

 Images are 2-D, discrete functions


 2-D Fourier transform uses product of sin’s and cos’s
(things carry over naturally)
 Fourier transform of a discrete, quantized function will
only contain discrete frequencies in quantized amounts
o In particular, we can store the Fourier transform of a
discrete image in the same amount of space as we can store
the image
 Numerical algorithm: Fast Fourier Transform (FFT)
computes discrete Fourier transforms
Point Sources and Delta Functions

 The signal processing concepts discussed in 1-D


case can be easily extended to 2-D cases.
 We will describe how to represent an image with
delta functions, linear operations on images and the
use of the Fourier transform.
 If any arbitrary picture f(x,y) could be considered to
be a sum of point sources, then a knowledge of the
operation’s output for a point source input could be
used to determine the output for f.
 Whereas for 1-D signal processing the response due
to a point source input is called the impulse response,
in image processing it is usually referred to as the
point spread function.
Point Sources and Delta Functions
1 | x | 1 / 2 and | y | 1 / 2
Let’ s define: rect ( x, y )  
0 elsewhere
1
And:  n  2 rect (nx, ny ), n  1, 2,, rect(x,
rect(x,y) y)
n
 n is zero outside the 1/n x 1/n 1
square and has constant value n2
inside that square. 0.8

 If we allow n approach infinity, then 0.6

we get the 2-D Dirac delta function


0.4
(x, y):
0.2

 x  y  0
 ( x, y )   0
-1
 0 otherwise
-1
-0.5
-0.5
0 0
0.5 0.5
1 1 x
y
Point Sources and Delta Functions
 Other properties of delta function  (x, y):
 ( x, y )   ( x, y )
 

   ( x, y ) dx dy  1
 
 

  g ( x, y ) ( x, y ) dx dy  g (0,0)
 
 

  g ( x, y ) ( x   , y   ) dx dy  g ( ,  )
 
“sifting” property
 

  exp  j2 (ux  vy)du dv   ( x, y )


 

 The point spread function, which is the output image for an input
point source at the origin of the xy-plane, is denoted by h(x, y).
Point Sources and Delta Functions
 Now let us consider an arbitrary input picture f (x, y). The picture can
be considered to be a linear sum of point sources:
 
f ( x, y )    f ( ,  ) (  x,   y ) d d
 

 In other words, the image f (x, y) is a linear sum of point sources located
at (, ) in the xy-plane with  and  ranging from -∞ to + ∞.
 If we apply a linear operation O on the picture f(x,y), then by the linearity
of the operation, it means that the response to a sum of excitations is
equal to the sum of responses to each excitation:
  
O f ( x, y )  O    f ( ,  ) ( x   , y   ) d d 
  
 
   f ( ,  )O ( x   , y   )d d
  
g ( x, y )  f ( x, y )  h( x, y )

 
   f ( ,  )h( x   , y   ) d d  g ( x, y )
  
Convolution of f and h
Point Sources and Delta Functions
(2-D Convolution Theorem)
 A simple change of variables can write the previous convolution into:
 
g ( x, y )    f ( x   , y   )h( ,  ) d d
 

Since g ( x, y )  f ( x, y )  h( x, y )  g ( x, y )  f ( x, y )

 Example: a blurring function h(x,y) to smooth out the edge of an image.

1 x 2  y 2  1 / 16
h ( x, y )  
0 elsewhere
Point Sources and Delta Functions
(2-D Convolution Theorem)
ex2_1_pointspreadfunction.m

f ( x, y )  h( x, y )  g ( x, y )

1 1
100
0.8 0.8
80
0.6 0.6
60

0.4 0.4
40

0.2 0.2 20

0 0 0
1 1
40
1 1
0.5 0.5 30 40
0 0 30
0 0 20
20
-0.5 -0.5 10 10
-1 -1 -1 -1
Point Sources and Delta Functions
(2-D Convolution Theorem)
ex2_1_pointspreadfunction.m

f ( x, y )  h( x, y )  g ( x, y )
5
50 50
10

100 100
15

150 20 150

25
200 200
30

250 35 250

40
300 300

45
350 350
100 200 300 400 10 20 30 40 100 200 300 400

>> help conv2


CONV2 Two dimensional convolution.
MATLAB C = CONV2(A, B) performs the 2-D convolution of matrices
A and B. If [ma,na] = size(A) and [mb,nb] = size(B), then
size(C) = [ma+mb-1,na+nb-1].
Point Sources and Delta Functions
(2-D Convolution Example)
ex2_1_pointspreadfunction.m %%% Example 2_2: image blurring filter
%% rect(x,y): pointspreadfunction
clear
%%% Example 2_2: image blurring filter N = 48;
%% rect(x,y): pointspreadfunction hxy = zeros(N,N);
clear ax = linspace(-1, 1, N);
N = 48; [X,Y] = meshgrid(ax,ax);
hxy = zeros(N,N); I = find(X.^2 + Y.^2<=1/16);
ax = linspace(-1, 1, N); hxy(I) = 1;
[X,Y] = meshgrid(ax,ax);
I = find(X.^2 + Y.^2<=1/16); %%% vaqueros gray image
hxy(I) = 1; img = ‘img_vaquerosgray.jpg';
fxy = double(imread(img));
rect = zeros(N,N); [nFx, nFy] = size(fxy);
rect(N/4+1:N*3/4,N/4+1:N*3/4) = 1;
gxy2 = conv2(fxy, hxy);
gxy = conv2(rect, hxy); [nGx2, nGy2] = size(gxy2);
[nGx, nGy] = size(gxy); nx2 = [ceil(nGx2/2-nFx/2)+1:ceil(nGx2/2+nFx/2)];
nx = [ceil(nGx/2-N/2)+1:ceil(nGx/2+N/2)]; ny2 = [ceil(nGy2/2-nFy/2)+1:ceil(nGy2/2+nFy/2)];
ny = [ceil(nGy/2-N/2)+1:ceil(nGy/2+N/2)]; gxy2 = gxy2(nx2,ny2);
gxy = gxy(nx,ny);
figure(3);
figure(2); subplot(1,3,1); h1 = image(fxy); axis tight; colormap(gray);
subplot(1,3,1); mesh(ax,ax,rect); axis tight; set(h1, 'CDataMapping', 'scaled');
subplot(1,3,2); mesh(ax,ax,hxy); axis tight; subplot(1,3,2); h2 = image(hxy); axis tight; colormap(gray);
subplot(1,3,3); mesh(gxy); axis tight; set(h2, 'CDataMapping', 'scaled');
colormap(gray*0); subplot(1,3,3); h3 = image(gxy2); axis tight;colormap(gray);
set(h3, 'CDataMapping', 'scaled');
2-D Convolution Theorem - Example
f ( x, y )  h( x, y )  g ( x, y )

F(u,v) X G(u,v) = F(u,v) G(u,v)

F-1[F(u,v) . G(u,v)]
Same!
2-D Continuous Fourier Transform
 
2-D Fourier Transform: F ( u, v )  
  
f ( x, y )e  j 2 ( uxvy )dxdy

Spatial frequency spectrum 2-D image space


 

 
j 2 ( ux vy )
Inverse Fourier Transform: f ( x, y )  F ( u , v ) e dudv
  

 Example: let f(xy) = rect(x,y)

1 | x | 1 / 2 and | y | 1 / 2 1/ 2 1/ 2
rect ( x, y )  
 
 j 2 ( ux vy )
F ( u, v )  e dxdy
0 elsewhere
1 / 2 1 / 2

sin u
1/ 2


 j 2vy
The pattern itself has a spatial period  e dy
of (u2 + v2)-1/2 along a direction that u 1 / 2
subtends an angle tan-1 (v/u) with the sin u sin v
x-axis.    sin c(u, v )
u v
2-D Fourier Transform
RECT = fftshift(fft2(rect));
rect(x,y) RECT(u,v)

sinc(u, v)

0.9
500
0.8

0.7 400
0.6

0.5 300

0.4
200
0.3
0.2
100
0.1

0 0
-1 1 -10 10
-0.5 0.5 -5 5
0 0 0 0

0.5 -0.5 5 -5
10 -10
1 -1 y v
x u
2-D Fourier Transform
RECT = fftshift(fft2(rect));

rect(x,y) RECT(u,v)
sinc(u, v)

1
60
0.9

0.8 50
0.7
0.6 40

0.5
30
0.4

0.3 20

0.2
10
0.1

0 0
-1 1 -10 10
-0.5 0.5 -5 5
0 0 0 0

0.5 -0.5 5 -5
10 -10
1 -1 y v
x u
2-D Fourier Transform
%%% Example 2_2: 2D FT
ex2_2_2DFT.m
clear
N = 48;
%% rect(x,y): pointspreadfunction
rect = zeros(N,N);
rect(N/4+1:N*3/4,N/4+1:N*3/4) = 1;
ax = linspace(-1, 1, N);
dx = ax(2) - ax(1);

RECT = fftshift(fft2(rect));
U = 1/dx*[-N/2:N/2-1]/N;
V = U;

%%% Display original 2-D image and RECT(u,v) 2-D FFT one
figure(1);
subplot(1,2,1); h1 = mesh(ax,ax,rect); xlabel('x'); ylabel('y');
axis tight; title('rect(x,y)'); view(45, 30);
colormap(gray*0); set(h1,'CDataMapping', 'scaled');
subplot(1,2,2); h2 = mesh(U,V,RECT); xlabel('u'); ylabel('v');
axis tight; title('RECT(u,v)'); view(45, 30);
colormap(gray*0); set(h2,'CDataMapping', 'scaled');
The 2-D Discrete Fourier Transform
 The 2-D Discrete Fourier Transform (DFT) is defined as:

MATLAB: F = fft2(f);
 The Inverse Discrete Fourier Transform (IDFT) is defined as:

MATLAB: f = ifft2(F);
 2-D Parseral’s Theorem:
Placing the Coefficients

-v
The 2-D Discrete Fourier Transform
 The Fourier transform represents an image in terms of
exponentials of the form ej2(ux+vy).

 For an image f(x,y), x = 0...M-1, y = 0...N-1, there are


two-indices basis functions Bu.v(x,y):

 Here we have shown the real (cosine) and the imaginary


(sine) parts of one such exponential.
The 2-D Discrete Fourier Transform
buv and b-u,-v have similar frequencies but inverted shifts.
V

u=-2, v=2 u=-1, v=2 u=0, v=2 u=1, v=2 u=2, v=2

u=-2, v=1 u=-1, v=1 u=0, v=1 u=1, v=1 u=2, v=1

U
u=-2, v=0 u=-1, v=0 u=0, v=0 u=1, v=0 u=2, v=0

u=-2, v=-1 u=-1, v=-1 u=0, v=-1 u=1, v=-1 u=2, v=-1

u=-2, v=-2 u=-1, v=-2 u=0, v=-2 u=1, v=-2 u=2, v=-2
Visualizing the Fourier Transform Image
in MATLAB
 F(u,v) is a Fourier transform of f(x,y) and it has complex entries.

F = fft2(f);
 To clearly display the Fourier Spectrum (amplitude) |F(u,v)|:
– Reduce dynamic range of |F(u,v)| by displaying the log:

D = log(1+abs(F));
– Cyclically rotate the image so that F(0,0) is in the center:

D = fftshift(D);
 Example:
|F(u)| = 100 4 2 1 0 0 1 2 4
log(1+|F(u)|) = 4.62 1.61 1.01 0.69 0 0 0.69 1.01 1.61
log(1+|F(u)|)/0.0462 = 10 4 2 1 0 0 1 2 4
fftshift(log(1+|F(u)|) = 0 1 2 4 10 4 2 1 0
Visualizing the Fourier Image
– MATLAB Example
Original f(x, y) |F(u,v)|

log(1 + |F(u,v)|) fftshift(log(1 + |F(u,v)|))


Change to log scale) (shift the 0 frequency to the center))
Visualizing the Fourier Image in MATLAB
Original f(x,y) |F(u, v)|

100 100

200 200

300 300

400 400

100 200 300 400 500 100 200 300 400 500

Can barely see a spot Shifted Fourier Image Shifted Log Fourier Image log(1+ |F(u,v)|)

100 100

200 200

300 300

400 400

100 200 300 400 500 100 200 300 400 500
Visualizing the Fourier Image in MATLAB
%%% Example 2_3_FFTimagedisplay
Clear
img = 'img_flower.jpg'; ex2_2_2DFT.m
fxy = double(imread(img)); % convert uint8 image data to floating

Fuv = fft2(fxy); %% 2-D FFT (complex)


Fuv2 = abs(fftshift(Fuv)); %% fftshift and amplitude
Fuv3 = log10(1+abs(fftshift(Fuv))); %% log scale

figure(2);
subplot(2,2,1); h1 = image(fxy); axis tight; title('Original f(x,y)');
colormap(gray); set(h1, 'CDataMapping', 'scaled');
subplot(2,2,2); h2 = image(abs(Fuv)); axis tight; title('|F(u, v)|');
colormap(gray); set(h2, 'CDataMapping', 'scaled');
subplot(2,2,3); h3 = image(Fuv2); axis tight; title('Shifted Fourier Image');
colormap(gray); set(h3, 'CDataMapping', 'scaled');
subplot(2,2,4); h4 = image(Fuv3); axis tight;
title('Shifted Log Fourier Image log(1+ |F(u,v)|)');
colormap(gray); set(h4, 'CDataMapping', 'scaled');
Visualizing the Fourier Image in MATLAB
Fuv_shift = fftshift(Fuv);
Fuv Fuv after fftshift
1 N/2 N N/2 N 1
M/2

M/2 M

M 1

Fuv Fuv after fftshift


Properties of the
2D Fourier Transform
(1) Symmetry of the FT for Real Signals
For real signals/images:
40
35
30
25
20
15
10
5
0
-5

-60 -40 -20 0 20 40 60


2-D DFT Properties
 Separability:

 So, performing a 2-D FT can be carried out in two steps:


1. Perform 1-D FT on EACH column of image f(x,y), obtaining F(x,v).
2. Perform 1-D FT on EACH row of F(x,v), obtaining F(u,v).

 Higher dimension Fourier Transform can be performed by


applying 1-D transform on each dimension a time.
2-D DFT Properties
 Translation:

 The Fourier Spectrum remains unchanged under translation:

 Rotation: Rotation of f(x,y) by   rotation of F(u,v) by 

If F f (r,  )  F (,  )

Then F f (r,    )  F (,    )

 Scaling:
Example - Rotation
Image f(x, y) Image - Rotated

2D FFT 2D FFT

Fourier Spectrum Fourier Spectrum


2-D Fourier Transform – Example 1
Image f(x, y) Frequency Spectrum F(u, v)
2-D Fourier Transform – Example 2
Image f(x, y) Frequency Spectrum F(u, v)
2-D Fourier Transform – Example 3
Image f(x, y) Frequency Spectrum F(u, v)
2-D Fourier Transform – Example 4
Image f(x, y) Frequency Spectrum F(u, v)
Phase and Magnitude

 Magnitude vs Phase
o Images have very samilar magnitude transform
o But, phase is very different from image to image

 Demonstration
o Take two pictures, swap the phase transforms,
compute the inverse - what does the result look
like?
Phase and Magnitude
The magnitude of
Original image
Fourier transform

2D FFT
The phase
transform

Original image
The magnitude of
Fourier transform

2D FFT

The phase
transform
Phase and Magnitude - swapping

Reconstruction with zebra phase, Reconstruction with cheetah phase,


cheetah magnitude zebra magnitude
Image Processing - Filters
Filters
• A filter is something that attenuates or enhances
particular frequencies
• Easiest to visualize in the frequency domain,
where filtering is defined as multiplication:

H ( )  F ( )  G( )
• Here, F is the spectrum of the function, G is the
spectrum of the filter, and H is the filtered
function. Multiplication is point-wise
Qualitative Filters

F  G = H

Low-pass
 =

 = High-pass

 Band-pass
=
Filtering in the Spatial Domain
• Filtering the spatial domain is achieved by convolution

h( x)  f  g   f (u) g ( x  u)du

• Qualitatively: Slide the filter to each position, x, then sum
up the function multiplied by the filter at that position

Convolution
Example
Images Filtering (LPF)
• Work in the discrete spatial domain
• Convert the filter into a matrix, the filter mask
• Move the matrix over each point in the image, multiply the entries by
the pixels below, then sum
• Filtering can be visualized by drawing a ”convolution kernel”.
• A kernel is a small grid showing how a pixel's filtered value depends
on its neighbors.
• To perform a low-pass filter (LPF) by simply averaging adjacent 3x3
pixels. Each pixel and its eight neighbors are multiplied by 1/9 and
added together. The pixel in the middle is replaced by the sum.
1 1 1 0 1 0
LPF1  1 1 1 LPF 2  1 4 1
1 1
9  8 
1 1 1 0 1 0

• This is repeated for each pixel in the image.


• If we didn't want to filter so harshly, we could change the kernel to
reduce the averaging.
Box Filter
• Box filters smooth by averaging neighbors
• In frequency domain, keeps low frequencies and
attenuates (reduces) high frequencies, so clearly a
low-pass filter

Spatial: Box Frequency: sinc

1 1 1
LPF1  1 1 1
1
9 
1 1 1
Images Filtering (HPF)
• A high-pass filter (HPF) can be used to make an image appear
sharper.
• These filters emphasize fine details in the image – exactly the
opposite of the low-pass filter.
• High-pass filtering works in exactly the same way as low-pass
filtering, but just uses a different convolution kernel.
• In the example below, notice the minus signs for the adjacent pixels.
If there is no change in intensity, nothing happens. But if one pixel is
brighter than its immediate neighbors, it gets boosted.
 0 1 0 
HPF   1 8  1
1
4 
 0  1 0 
• While low-pass filtering smooths out noise, high-pass filtering does
the opposite: it amplifies noise.
• High-pass filtering can also cause small, faint details to be greatly
exaggerated.
Filtering Algorithm

 If Iinput is the input image, and Ioutput is the


output image, M is the filter mask and k is the
mask size:
k /2 k /2
I output[ x][ y]   I
i  k / 2 j  k / 2
[ x  i][ y  j ]M [i  k / 2][ j  k / 2]
input

 Care must taken at the boundary


– Make the output image smaller
– Extend the input image in some way
Image Filtering - Example

LPF

HPF
Image Filtering – MATLAB Example
ex3_1_imagefilters.m

clear
img = imread('ex-image1.jpg', 'jpg');
[M, N] = size(img);

LPF1 = ones(5)/25;
F = LPF1; MATLAB function:

K = floor(size(F)/2); K = K(1);
k = [-K:K]; imread( )
img_out = zeros(size(img));
for m = 1+K:M-K,
imfinfo( )
for n = 1+K:N-K, imwrite( )
win = double(img(m+k, n+k)).*F; imformats( )
img_out(m, n) = floor(sum(win(:))); image( )
end;
end; uint( )
double( )
figure(1); colormap( )
subplot(1,2,1); imagesc(img); legend('Input');
axis tight; axis square; colormap(gray);
subplot(1,2,2); imagesc(img_out); legend('Output');
axis tight; axis square; colormap(gray);
Image Processing - Sampling
Sampling The Image
 Sampling a function f(x) with impulse train of cycle T
produces replicas in the frequency domain with cycle
1/T:
f(x) |F()|
Continuous
^F

x 

f(x)
*
|F()|
^F

x
T Fs = 1/T

=
=

f(x) |F()|
Discrete ^F


x -1/2T 1/2T
Cyclic and Symmetry of Discrete Signals
1 cycle

-N/2 0 N/2 N-1


Due to replicas: F(k)=F(N+k)
Due to symmetry: F(k)=F*(-k)=F*(N-k)

In 2D: Fu, v   Fu  N, v   Fu, v  M  Fu  N, v  M


Undersampling and Aliasing
f(x) ^ |F()|
F
x 
f(x)
^
|F()| *
F

x
T 1/T |F()|
f(x) ^
F

x -1/2T 1/2T

|F()|
f(x)
^
F

x
T’ 1/T’
|F()|
f(x) ^
F

x -1/2T’ 1/2T’
Critical Sampling
• If the maximal frequency of f(x) is max, it is clear from
the above replicas that max should be smaller that
1/2T.
1
• Alternatively:  2max
T

• Nyquist Theorem: If the maximal frequency of f(x) is


max the sampling rate should be larger than 2max in
order to fully reconstruct f(x) from its samples.
2max is called the Nyquist frequency.
• If the sampling rate is smaller than 2max overlapping
replicas produce aliasing.
|F()|


-1/2T 1/2T
Critical Sampling & Aliasing

Input Input

Reconstructed Reconstructed
Aliasing
Aliasing in Color Images
 Image demosaicing may produce aliasing in color planes.
Sampling the Transform
 Sampling a function F() with impulse train of cycle S
produces replicas in the image domain with cycle 1/S:
f(x) |F()|
^ -1
F

x 

*
^F-1

x 
S
1/S

^-1
F |F()|
f(x)

x 
Sampling Image & Transform
 Sampling both f(x) with impulse train of cycle T and F() with
impulse train of cycle S:
f(x) |F()|
^F

x 
*
^F

x
T 1/T
^
F

x -1/2T 1/2T

^-1
F

... ... S
1/T
1/S
Number of Samples
• Question: Assuming f(x) was samples with N samples.
What is the minimal number of samples in F() in order
to fully reconstruct f(x) ?
• Answer:
– If we sample f(x) with N samples of cycle T, the support of
f(x) is NT.
– The support of F() is 1/T in the frequency domain.
– If we sample F() with M samples, the sample cycle is 1/MT.
– The replicas in the spatial domain are each MT.
– In order to avoid replicas overlap, MT should be equal or
bigger than NT (the function support).

M N
Optimal Interpolation
 If sampling rate is above Nyquist - it is possible to fully
reconstruct f(x) from its samples:

f(x) |F()|
^-1
F

x -1/2T 1/2T

*
f(x) |F()|
^-1
F
1

x -1/2T 1/2T

f(x) |F()|
^-1
F

x -1/2T 1/2T
Image Scaling
 How is it possible to scale a digitized image?

f(x) |F()|
^
F

T x 
-1/2T 1/2T

f(x) |F()|
^
F

x 
T/2 -1/T 1/T

We can zero-pad the frequency


spectrum to interpolate the image
Image Scaling: Example 1
f(x, y) F(u, v)
^
F

Scaled (interpolated) f(x, y)

^
F-1

Zero-padding in F(u, v)
Image Scaling: Example 2
Original f(x,y) fftshift(F(u, v))

50 50

100
^
F 100

150 150

200 200

250 250

300 300

350 350
100 200 300 400 100 200 300 400

Scaled f(x,y) Zero-padded fftshift(F(u, v))


100 100

200 ^
F-1 200

300 300

400 400

500 500

600 600

700 700
200 400 600 800 200 400 600 800
Image Scaling: Example 2
ex2_4_imagescaling.m
%%% Example 2_4_imagescaling
Clear
img = 'img_vaquerosgray.jpg';
fxy = double(imread(img)); %% original f(x,y),convert from uint8 to floating data
[nFx, nFy] = size(fxy);

Fuv = fftshift(fft2(fxy)); %% Fourier frequency spectrum F(u, v)


[nFu, nFv] = size(Fuv);
Fuv2 = zeros(2*nFu, 2*nFv); %% zero-padding
Fuv2(1:nFu, 1:nFv) = Fuv; %% zero-padding

fxy2 = ifft2(Fuv2); %% IFFT back to image domain


fxy2 = fxy2/max(abs(fxy2(:)))*255; %% nomalize the new image

figure(4);
subplot(2,2,1); h1 = image(fxy); axis tight; title('Original f(x,y)');
colormap(gray); set(h1, 'CDataMapping', 'scaled');
subplot(2,2,2); h2 = image(log10(abs(Fuv)+1)); axis tight; title('F(u, v)');
colormap(gray); set(h2, 'CDataMapping', 'scaled');
subplot(2,2,4); h3 = image(log10(abs(Fuv2)+1)); axis tight; title('Zero-padded F(u,v)');
colormap(gray); set(h3, 'CDataMapping', 'scaled');
subplot(2,2,3); h4 = image(abs(fxy2)); axis tight; title('Scaled f(x,y)');
colormap(gray); set(h4, 'CDataMapping', 'scaled');

You might also like