Image Transformation
Image Transformation
B C Dhara
Department of Information Technology
Jadavpur University
Introduction and Overview
A transform is essentially a mathematical
mapping
Used in image analysis and processing to
provide information regarding the rate at
which the gray levels change within an
image – the spatial frequency content of
an image
2
A transform maps image data into a
different mathematical space via a
transformation equation
Most of the discrete transforms map the
image data from the spatial domain to the
frequency domain (also called the spectral
domain), where all the pixels in the input
(spatial domain) contribute to each value
in the output (frequency domain)
3
Why do we need a transform?
Mathematical transformation are applied to
the signals to obtain a further information
from the signal that is not readily available in
the raw signal.
4
Discrete Transforms
5
Representation of functions
using orthogonal functions
Consider the problem of points
representation in 2D?
distance between every pair
Consider a pair of axis
Orthogonal/non-orthogonal
What about the representation of
functions?
6
7
Orthogonal functions
A collection of functions {Φi | I=1,2,…}
Is said to be orthogonal if
8
Orthogonal functions
9
The general form of the transformation equation,
assuming an N x N image, is given by:
where
u and v are the frequency domain variables,
k is a constant that is transform dependent,
T(u, v) are the transform coefficients,
and B(r, c; u, v) correspond to the basis images
10
Basis images should be orthogonal and
orthonormal
11
The lowest spatial frequency, called the
zero frequency term ( DC term),
corresponds to an image with a constant
value
12
13
The transform coefficients, T(u,v), are the
projections of I(r,c) onto each B(u,v)
14
15
Example
Let I(r,c) =
and let
B(u,v;r,c) =
16
Then T(u,v) =
17
To obtain the image from the transform
coefficients we apply the inverse transform
equation:
18
Example
19
Is this correct?
No, since I(r,c) =
21
What is 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 coefficients.
This representation is called Fourier series.
No matter how complex is the function.
Even functions that are not periodic can be
expressed as the integral of sines and/or
cosines multiplied by a weighting function. This
formulation is known as Fourier Transform
22
Note
A function expressed either by Fourier
series/ transform, can be reconstructed
(recovered) computing by inverse
process, without any loss.
23
x(t)=cos(2pi10t) + cos(2pi25t) + cos(2pi50t) + cos(2pi100t)
24
Fourier Transform
25
Fourier Transform
The FT of a function is the set of
coordinates representing the function in
an infinite dimensional space spanned
by orthogonal basis vector {e-j2Πux | -α
< u < α} and mathematically,
26
Inverse Fourier Transform
29
Fourier Transform Example
30
2D- Fourier Pair
F(u,v) = ∫∫ f(x,y) e-j2Π(ux + vy) dx dy
f(x,y) = ∫∫ F(u,v) ej2Π(ux + vy) du dv
31
Discrete Fourier Transform (DFT)
Consider N sample points:
x0, x0+Δx , x0+2Δx , …, x0+(N-1)Δx; Δx sampling
rate
f(i) = f(x0+ i Δx)
f(0), f(1), f(2)….,f(N-1)
F(u) = 1/N Σ[f(x). e-j2Πux/N]; u= 0,1,…,N-1
f(x) = Σ[F(u). e j2Πux/N]; x=0,1,…,N-1
F(u) = F(u Δu); and N sample points in one
period then the relation is Δu = 1/(N. Δx)
f(0)=2, f(1)=3, f(2)=4, f(3)=4?
F(0) = 1/N Σ[f(x). e-j2Π0x/N] = 1/N Σf(x) 32
Example of FT (1-D)
Twice the width of the function
Double the area under the curve
peak value is twice the previous one
Number of zeros in transform is just double
33
Example: Given I(c) = [3,2,2,1], corresponding to the brightness values
of one row of a digital image. Find F (v) in rectangular and exponential form
34
2D- DFT
F(u,v) = 1/(MN) Σ Σ f(x,y) e-j2Π (ux/M + vy/N)
35
Notes
Fourier Spectrum
|F(u,v)| =(R2(u,v) + I2(u,v))½
Phase Angle
Φ(u,v) = tan-1|I(u,v)/R(u,v)|
Power spectra
P(u,v) = |F(u,v)|2
36
Fourier Transform Example (contd)
37
• Linearity
The Fourier transform is a linear operator
and is shown by the following equations:
38
Separability
F(u,v) = 1/N Σ Σ f(x,y) e-j2Π (ux/N + vy/N)
= 1/N [Σ[ N/N Σ f(x,y) e-j2Π vy/N ] e-j2Π ux/N ]
= 1/N [Σ F(x,v) e-j2Π ux/N ]
39
Translation
g(x,y) = f(x,y) ej2 Π (u0x + u0y)/N
40
Periodicity
DFT, IDFT are periodic with period N
ie.,
F(u,v) = F(u+N,v) = F(u,v+N) = F(u+N,
v+N)
41
Conjugate Symmetry
F(u,v) = F*(-u,-v), if f(x,y) real
42
Inverse Transform using
Forward
F(u) = 1/N Σ f(x) e –j2Πxu/N ; u=0,1,…,N-1
f(x) = Σ[F(u). ej2Πux/N]; x=0,1,…,N-1
43
Rotation
x = r cos(θ), y = r sin(θ)
u = w cos(Ф), v= w sin(Ф)
f(x,y) ↔ F(u,v)
f(r, θ) ↔ F(w, Ф)
f(r, θ+ θ0 ) ↔ F(w, Ф + θ0)
44
Distributivity & Scaling
FT(f(x,y) + g(x,y)) = FT(f(x,y)) + FT(g(x,y))
a.f(x,y) a.F(x,y)
f(α) = 1 , 0 ≤ α ≤ 1
g(α) = ½ , 0 ≤ α ≤ 1, find the convolution
between them.
46
Convolution
0 1
f 0 1
g
-1 0
-g 47
Example of convolution
-1 0 x
g(x-α)
48
Convolution
Value is 0
-1 0 1
g At f
x=0
49
Convolution
Value is x/2
-1 0 x 1
At
0≤x≤1
50
Convolution
Value is 0
0 1 x=2
At x=2
51
Convolution
Value is 1- x/2
-1 0 1 x
At
1≤x≤2
Length is 1-(x-1)
52
Convolution Theorem
f(x) → F(u)
g(x) → G(u)
53
2-D convolution
f(x,y) * g(x,y) =
Convolution theorem
f(x,y) * g(x,y) ↔ F(u,v) G(u,v)
f(x,y) g(x,y) ↔ F(u,v) * G(u,v)
54
Discrete Convolution
f(x) * g(y) =
f(x,y) * g(x,y) =
55
Correlation
Continues
f ( x) g ( x) f * ( ) g ( x ) d
M 1
Discrete 1
f ( x) g ( x)
M m 0
f ( m) g ( x m)
for x 0,1,2,..., M 1
56
2D-Correlation (cont.)
f ( x , y ) g ( x, y ) f * ( , ) g ( x , y ) d d
1 M 1 N 1
f ( x, y ) g ( x, y )
MN m 0 n 0
f (m, n) g ( x m, y n)
57
Correlation Theorem
f ( x, y ) g ( x, y ) F * (u, v)G (u, v)
and
f * ( x, y ) g ( x, y ) F (u, v)G (u, v)
58
Fast Fourier Transform
F(u) = 1/N Σ[f(x). e-j2Πux/N]; u=
0,1,…,N-1
59
Fast Fourier Transform
F(u) = 1/N Σ[f(x). e-j2Πux/N]
= 1/N Σ[f(x). e-j2Π/N . ux]
ux
= 1/N Σ[f(x). wN ]
we assume N = 2n , n > 0, N = 2M
ux
F(u) = 1/2M Σ[f(x). w2M ]
u2x
= ½{ 1/M Σ[f(2x). w2M ] +
u(2x+1)
1/M Σ[f(2x+1). w2M ]}
ux u2x
wN = e-j2Π/N . ux w2M = (e-j2Π/2M)2ux
60
Fast Fourier Transform
u2x
w2M = (e-j2Π/2M)2ux
ux
=e -j2Πux/M = (e-j2Π/M ) = wM
ux
u2x
F(u) = ½{ 1/M Σ[f(2x). w2M ] +
u(2x+1)
1/M Σ[f(2x+1). w2M ]}
ux
= ½{1/M Σ[f(2x). wM ] + 1/M
2ux u
Σ[f(2x+1). w2M w2M ]
u
= ½ [Feven (u) + Fodd (u). w2M ]
61
Fast Fourier Transform
u
F(u) = ½ [Feven (u) + Fodd (u). w2M ]
F(u + M) = ½ [Feven (u) - Fodd (u).
u u+M u
w2M ] (prove it, hints: wM = wM
u+M u
w2M = -w2M )
For u=0,1….,M-1 F(u) and F(u+M)
covers all
62
Complexity analysis
n=1, i.e., two sample points F(0) and F(1)
Feven(0) = with only sample point at x=0
Fodd(0) = with only sample point at x=1
no multiplication, no addition
F(0) requires one multiplication [Fodd(0) by w20 ]
and one addition
F(1) need only one addition (subtraction)
m(1) =1 and a(1) =2
63
Complexity analysis
In n=2, 4 sample points
Feven contains 2 even points {x0, x2}
Similarly, Fodd contains 2 even points {x1, x3}
Two points requires m(1) and a(1)
So, 2m(1) and 2a(1)
F(0) and F(1) needs two multiplications and
two additions
F(2), and F(3): two subtraction (addition)
m(2) =2 m(1)+2 and a(2) = 2a(1)+4
64
Complexity analysis
Similarly, m(3) = 2 m(2) + 4 and a(3)
= 2 a(2) + 8
In general, m(n) =2 m(n-1) + 2n-1 and
a(n) = 2 a(n-1) + 2n where a(1)=2 and
m(1)=1
Prove that, m(n) = (n. 2n)/2 and a(n) =
n. 2n
65
Discrete Cosine Transform
(DCT)
Uses sinusoidal basis functions like the
Fourier transform
Cosine Transform has following properties
unlike Fourier Transform:
• Basis functions are not complex
• Uses only cosine functions, and not sine
functions
• Requires only real arithmetic
66
The two-dimensional discrete cosine
transform (DCT) equation for an N x N
image is given by:
where
67
The DCT has been used historically in
image compression, such as JPEG
68
69
2D basis function of DCT
70
The inverse cosine transform is given by:
C-1[C(u,v)] = I(r,c) =
71
2D-DCT
image block
55 36 34 25 66 35 4 37
55 25 12 48 59 38 2 41
51 40 43 54 51 42 3 39
49 49 51 49 51 37 3 39
50 50 51 48 54 36 2 43
51 52 52 51 55 41 4 41 DC component
51 51 52 54 55 42 1 45
52 51 53 51 53 42 2 41
low frequency
313 56 27 18 78 60 27 27
38 27 13 44 32 1 24 10
20 17 10 33 21 6 16 9
10 8 9 17 9 10 13 1
6 1 6 4 3 7 5 5
2 3 0 3 7 4 0 3
4 4 1 2 9 0 2 4
3 1 0 4 2 1 3 1
high frequency
DCT block
72
WALSH-HADAMARD
TRANSFORM (WHT)
Basis functions are not sinusoids
The basis functions are based on square
or rectangular waves with peaks of +(-)1
Rectangular wave refers to any function
of this form, where the width of the pulse
may vary
Computations are very simple
73
74
The WHT equation is given by: n 1
1 N 1 bi ( x ) pi (u )
WH (u )
N
x 0
f ( x)( 1) i0
n 1
1 N 1 bi ( x ) pi (u )
f ( x)
N
WH
x 0
(u )( 1) i 0
where
N = 2n, the exponent on the (-1) is performed in
modulo 2 arithmetic, and
bi (r) is found by considering r as a binary
number, and finding the ith bit
75
EXAMPLE
n = 3 (3 bits, so N = 8), and r = 4
r in binary is 100, so b2(r) = 1, b1(r) = 0,
and b0(r) = 0
EXAMPLE
n = 4, (4 bits, so N = 16), and r = 2
r in binary is 0010, so b3(r) = 0, b2(r) = 0,
b1(r) = 1, and b0(r) = 0
76
pi (u) is found as follows:
77
Walsh-Hadamard transform cannot be
called a frequency transform, as the basis
functions do not exhibit the frequency
concept in the manner of sinusoidal
functions
Therefore instead of frequency terms, we
have sequency terms
Sequency is the number of zero crossings
(or sign changes)
78
79
2D-WHT
WHT transform pair
n1
1 N 1 N 1 bi ( x ) pi (u ) bi ( y ) pi ( v )
WH (u, v)
N
x 0 y 0
f ( x, y )( 1) i0
n1
1 N 1 N 1 bi ( x ) pi (u ) bi ( y ) pi ( v )
f ( x, y )
N
u 0
WH
v 0
(u , v )( 1) i 0
80
White +
Black -
81
Separable means that the basis function
can be expressed as a product of terms
that depend only on one of the variable
pairs, r,u or c,v, and that this separability
also allows us to perform the 2-D
transformation by two 1-D transforms
82
Haar Transform
The Haar transform has rectangular waves
as basis functions
Basis vectors contain not just +1 and -1,
but also contain zeros
The Haar transform is derived from the
Haar matrices
Each row in matrices represents a one-
dimensional basis vector
83
Basis vectors for a Haar transform of two
basis vectors (N = 2), four basis vectors
(N = 4) and eight basis vectors (N = 8) are:
84
The Haar basis vectors can be extended
to higher orders by following the same
patterns shown in the previous slide
As the order increases the number of
zeros in the basis vectors increase
This has the unique effect of allowing a
multiresolution decomposition of an input
image
The Haar transform retains both spatial
and sequency information
85
Haar Transform
86