You are on page 1of 48

Digital Image Processing

Filtering in the Frequency Domain


(Circulant Matrices and Convolution)
Christophoros Nikou
cnikou@cs.uoi.gr

University of Ioannina - Department of Computer Science

Toeplitz matrices

Elements with constant value along the main


diagonal and sub-diagonals.
For a NxN matrix, its elements are determined by
a (2N-1)-length sequence {tn | ( N 1) n N 1}

T(m, n) = tm n

t0
t
1
T = t2

N 1

t1 t2 t( N 1)

t0 t1

t2

t1
t2 t1 t0 NN

C. Nikou Digital Image Processing (E12)

Toeplitz matrices (cont.)

Each row (column) is generated by a shift of the


previous row (column).
The last element disappears.
A new element appears.

T(m, n) = tm n

t0
t
1
T = t2

N 1

t1 t2 t( N 1)

t0 t1

t2

t1
t2 t1 t0 NN

C. Nikou Digital Image Processing (E12)

Circulant matrices
Elements with constant value along the main
diagonal and sub-diagonals.
For a NxN matrix, its elements are determined by
a N-length sequence {cn | 0 n N 1}

c1 c2
c0
c
C(m, n) = c( m n ) mod N
c
c
0
1
N 1

C = cN 2

c1
c2 cN 1
C. Nikou Digital Image Processing (E12)

cN 1

c2

c1
c0 NN

Circulant matrices (cont.)


Special case of a Toeplitz matrix.
Each row (column) is generated by a circular shift
(modulo N) of the previous row (column).

c1 c2
c0
c
C(m, n) = c( m n ) mod N
c
c
0
1
N 1

C = cN 2

c1
c2 cN 1
C. Nikou Digital Image Processing (E12)

cN 1

c2

c1
c0 NN

Convolution by matrix-vector
operations
1-D linear convolution between two discrete
signals may be expressed as the product of a
Toeplitz matrix constructed by the elements of
one of the signals and a vector constructed by the
elements of the other signal.
1-D circular convolution between two discrete
signals may be expressed as the product of a
circulant matrix constructed by the elements of
one of the signals and a vector constructed by the
elements of the other signal.
Extension to 2D signals.
C. Nikou Digital Image Processing (E12)

1D linear convolution using Toeplitz


matrices
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

The linear convolution g[n]=f [n]*h [n] will be of


length N=N1+N2-1=3+2-1=4.
We create a Toeplitz matrix H from the
elements of h [n] (zero-padded if needed) with
N=4 lines (the length of the result).
N1=3 columns (the length of f [n]).
The two signals may be interchanged.
C. Nikou Digital Image Processing (E12)

1D linear convolution using Toeplitz


matrices (cont.)
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

1 0 0
1 1 0

H=
0 1 1

0 0 1 43
Length of f [n] = 3
Zero-padded h[n] in the first column

Length of the result =4


Notice that H is not
circulant (e.g. a -1
appears in the second line
which is not present in the
first line.

C. Nikou Digital Image Processing (E12)

1D linear convolution using Toeplitz


matrices (cont.)
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

1 0 0
1
1 1 0 1 1


g = Hf =
=
2
0 1 1 0

2
0 0 1
2
g[n] = {1, 1, 0, 2}
C. Nikou Digital Image Processing (E12)

10

1D circular convolution using


circulant matrices
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

The circular convolution g[n]=f [n]h [n] will


be of length N=max{N1, N2}=3.
We create a circulant matrix H from the
elements of h [n] (zero-padded if needed)
of size NxN.
The two signals may be interchanged.

C. Nikou Digital Image Processing (E12)

11

1D circular convolution using


circulant matrices (cont.)
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

1 0 1
H = 1 1 0
0 1 1 33
Zero-padded h[n] in the
first column
C. Nikou Digital Image Processing (E12)

12

1D circular convolution using


circulant matrices (cont.)
f [n] = {1, 2, 2}, h[n] = {1, 1}, N1 = 3, N 2 = 2

1 0 1 1 1
g = Hf = 1 1 0 2 = 1
0 1 1 2 0
g[n] == { 1, 1, 0}

C. Nikou Digital Image Processing (E12)

Block matrices

13

A11
A
A = 21

AM 1

A12
A22
AM 2

A1N
A2 N

AMN

Aij are matrices.


If the structure of A, with respect to its sub-matrices, is
Toeplitz (circulant) then matrix A is called block-Toeplitz
(block-circulant).
If each individual Aij is also a Toeplitz (circulant) matrix then
A is called doubly block-Toeplitz (doubly block-circulant).
C. Nikou Digital Image Processing (E12)

14

2D linear convolution using doubly


block Toeplitz matrices
m

m
1 4 1
2 5 3
f [m,n]
M1=2, N1=3

1 1
1 -1

h [m,n]
M2=2, N2=2

The result will be of size (M1+M2-1) x (N1+N2-1) = 3 x 4


C. Nikou Digital Image Processing (E12)

15

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
1 4 1
2 5 3
f [m,n]

1 1
1 -1

h [m,n]

At first, h[m,n] is zero-padded


m
to 3 x 4 (the size of the
0 0 0 0
result).
1 1 0 0
Then, for each row of h[m,n],
1 -1 0 0
a Toeplitz matrix with 3
columns (the number of
h[m,n]
columns of f [m,n]) is
constructed.
C. Nikou Digital Image Processing (E12)

2D linear convolution using doubly


block Toeplitz matrices (cont.)

16

m
0 0 0 0
1 1 0 0
1 -1 0 0
h[m,n]
1 0 0
1 1 0

H1 =
0 1 1

0 0 1

For each row of h[m,n], a


Toeplitz matrix with 3 columns
(the number of columns of f
[m,n]) is constructed.

1
1
H2 =
0

0
1
1
0

0
0
1

C. Nikou Digital Image Processing (E12)

0
0
H3 =
0

0 0
0 0
0 0

0 0

17

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
1 4 1
2 5 3

1 1
1 -1
h [m,n]

f [m,n]
Using matrices H1, H2
and H3 as elements, a
doubly block Toeplitz
matrix H is then
constructed with 2
columns (the number of
rows of f [m,n]).

H1
H = H 2
H 3

H3
H1
H 2 126

C. Nikou Digital Image Processing (E12)

18

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
1 4 1
2 5 3
f [m,n]

We now construct
a vector from the
elements of f [m,n].

1 1
1 -1
h [m,n]
2
5

3 (2 5 3)T
f = =
T
1 (1 4 1)
4

1

C. Nikou Digital Image Processing (E12)

19

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
1 4 1
2 5 3

1 1
1 -1

h [m,n]

f [m,n]
H1

g = Hf = H 2
H 3

2
5
H3
3

H1
1

H 2
4

1

C. Nikou Digital Image Processing (E12)

20

2D linear convolution using doubly


block Toeplitz matrices (cont.)

1 0 0 0 0 0
2
1 1 0 0 0 0
3


0 1 1 0 0 0
2


0
0
1
0
0
0
2

3
1 0 0 1 0 0 5 3

(2 3 2 3)T
1 1 0 1 1 0 3 10

T
g = Hf =
= = (3 10 5 2)

0 1 1 0 1 1 1
5

(1 5 5 1)T

0 0 1 0 0 1 4 2
0 0 0 1 0 0 1 1


0 0 0 1 1 0
5


0
0
0
0
1
1

5
0 0 0 0 0 1
1
C. Nikou Digital Image Processing (E12)

2D linear convolution using doubly


block Toeplitz matrices (cont.)

21

m
1 4 1
2 5 3

1 1
1 -1

h [m,n]

f [m,n]
m

1 5 5 1
3 10 5 2
2 3 -2 3

(2 3 2 3)T

T
g = (3 10 5 2)
(1 5 5 1)T

g [m,n]
C. Nikou Digital Image Processing (E12)

22

2D linear convolution using doubly


block Toeplitz matrices (cont.)

Another example
m

m
3 4
1 2

f [m,n]
M1=2, N1=2

1 -1

h [m,n]
M2=1, N2=2

The result will be of size (M1+M2-1) x (N1+N2-1) = 2 x 3


C. Nikou Digital Image Processing (E12)

23

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
3 4
1 2
f [m,n]

1 -1

h [m,n]

At first, h[m,n] is zero-padded


m
to 2 x 3 (the size of the
result).
0 0 0
Then, for each line of h[m,n],
1 -1 0
a Toeplitz matrix with 2
columns (the number of
h[m,n]
columns of f [m,n]) is
constructed.
C. Nikou Digital Image Processing (E12)

2D linear convolution using doubly


block Toeplitz matrices (cont.)

24

m
0 0 0
1 -1 0
h[m,n]
1 0
H1 = 1 1
0 1

For each row of h[m,n], a Toeplitz


matrix with 2 columns (the
number of columns of f [m,n]) is
constructed.
n
0 0
H 2 = 0 0
0 0

C. Nikou Digital Image Processing (E12)

25

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
3 4
1 2

1 -1
h [m,n]

f [m,n]
Using matrices H1 and
H2 as elements, a
doubly block Toeplitz
matrix H is then
constructed with 2
columns (the number of
rows of f [m,n]).

H1
H=
H 2

H2
H1 64

C. Nikou Digital Image Processing (E12)

26

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
3 4
1 2

f [m,n]

We now construct a
vector from the elements
of f [m,n].

1 -1
h [m,n]
1
2 (1 2)T
f = =
T
3 (3 4)

4

C. Nikou Digital Image Processing (E12)

27

2D linear convolution using doubly


block Toeplitz matrices (cont.)
m

m
3 4
1 2

f [m,n]

H1
g = Hf =
H 2

1 -1
h [m,n]

1
H 2 2

H1 3

4

C. Nikou Digital Image Processing (E12)

28

2D linear convolution using doubly


block Toeplitz matrices (cont.)

1 0 0 0
1
1 1 0 0 1
1


0 1 0 0 2 2 (1 1 2)T
g = Hf =
= =
T
0 0 1 0 3 3 (3 1 4)
0 0 1 1 4 1


0 0 0 1
4

C. Nikou Digital Image Processing (E12)

2D linear convolution using doubly


block Toeplitz matrices (cont.)

29

3 4
1 2

1 -1

h [m,n]

f [m,n]
m

3 1 4
1 1 -2

(1 1 2)T
g=
T
(3 1 4)

g [m,n]
C. Nikou Digital Image Processing (E12)

30

2D circular convolution using doubly


block circulant matrices

The circular convolution g[m,n]=f [m,n]h [m,n]


with 0 m M 1, 0 n N 1,
may be expressed in matrix-vector form as:

g = Hf
where H is a doubly block circulant matrix
generated by h [m,n] and f is a vectorized form
of f [m,n].
C. Nikou Digital Image Processing (E12)

31

2D circular convolution using doubly


block circulant matrices (cont.)
H0
H
1
H = H2

HM 1

HM 1
H0
H1
HM 2

HM 2 H1
HM 1 H2
H0
H3

HM 3 H0

Each Hj, for j=1,..M, is a circulant matrix with N


columns (the number of columns of f [m,n])
generated from the elements of the j-th row of
h [m,n].
C. Nikou Digital Image Processing (E12)

32

2D circular convolution using doubly


block circulant matrices (cont.)
h[ j, N 1] h[ j,1]
h[ j,0]
h[ j,1]

h
[
j
,0]
h
[
j
,
2]

Hj =

h[ j, N 1] h[ j, N 2] h[ j,0] NN

Each Hj, for j=1,..M, is a NxN circulant matrix


generated from the elements of the j-th row of
h [m,n].
C. Nikou Digital Image Processing (E12)

33

2D circular convolution using doubly


block circulant matrices (cont.)
m

m
0 1 0
1 3 -1
1 2 1

f [m,n]
1 0 1
H 0 = 1 1 0
0 1 1

1 0 0
H1 = 0 1 0
0 0 1

0 0 0
1 0 0
1 -1 0

h [m,n]
0 0 0
H 2 = 0 0 0
0 0 0

C. Nikou Digital Image Processing (E12)

34

2D circular convolution using doubly


block circulant matrices (cont.)
m

m
0 1 0
1 3 -1
1 2 1

f [m,n]
H0
g = Hf = H1
H 2

H2
H0
H1

0 0 0
1 0 0
1 -1 0
h [m,n]

H1 (1 2 1)
T

H 2 (1 3 1)

H 0 ( 0 1 0 )T

C. Nikou Digital Image Processing (E12)

35

2D circular convolution using doubly


block circulant matrices (cont.)
1 0 1 0 0 0 1 0 0 1 0
1 1 1 0 0 0 0 1 0 2 2


0 1 0 0 0 0 0 0 1 1 1


1
0
0
1
0
1
0
0
0

1 3
g = Hf = 0 1 0 1 1 1 0 0 0 3 = 4


0 0 1 0 1 0 0 0 0 1 3
0 0 0 0 0 0 1 0 1 0 1


0 0 0 0 0 0 1 1 1 1 4
0 0 0 0 0 0 0 1 0 0 2

C. Nikou Digital Image Processing (E12)

36

2D circular convolution using doubly


block circulant matrices (cont.)
m

m
0 1 0
1 3 -1
1 2 1

f [m,n]

1 4 -2
3 4 -3
0 2 -1

0 0 0
1 0 0
1 -1 0
h [m,n]

( 0 2 1)T

T
g = ( 3 4 3)

T
(1 4 2 )

g [m,n]
C. Nikou Digital Image Processing (E12)

37

Diagonalization of circulant matrices


Theorem: The columns of the inverse DFT matrix
are eigenvectors of any circulant matrix. The
corresponding eigenvalues are the DFT values of
the signal generating the circulant matrix.
Proof: Let

wN = e

2
j

w =e
nk
N

2 n
j
k

be the DFT basis elements of length N with:

0 k N 1, 0 n N 1,
C. Nikou Digital Image Processing (E12)

38

Diagonalization of circulant matrices


(cont.)
We know that the DFT F [k] of a 1D signal f [n]
may be expressed in matrix-vector form:

F = Af
where

f = [ f [0], f [1],..., f [ N 1]] , F = [ F [0], F [1],..., F [ N 1]]


T

( w0 ) 0
N
1 0
(w )
A= N

( w N 1 )0
N

(w )
(w )

0 1
N

1 1
N

(w )
(w )
0
N

1
N

(w ) (w )
N 1 1
N

N 1 2
N

(w )
(w )

1 N 1

1
N
( wNN 1 )

C. Nikou Digital Image Processing (E12)

0
N

N 1

Diagonalization of circulant matrices


(cont.)

39

The inverse DFT is then expressed by:


-1

f =A F
where
1
* T
A = (A )
N
1

0
( wN )
1 0
1 ( wN )
=
N

N 1 0
( wN )

( wN0 )

( wN0 )

(w )

(w )

1 1
N

1
N

(w ) (w )
N 1 1
N

N 1 2
N

( wN0 )

1 N 1
( wN )

N
1

( wNN 1 )

N 1

* T

The theorem implies that any circulant matrix has


eigenvectors the columns of A-1.
C. Nikou Digital Image Processing (E12)

40

Diagonalization of circulant matrices


(cont.)

Let H be a NxN circulant matrix generated by the 1D


N-length signal h[n], that is:

H (m, n) = h [ (m n) mod N ] h[m n]N


Let also k be the k-th column of the inverse DFT
matrix A-1.
We will prove that k, for any k, is an eigenvector of H.

The m-th element of the vector Hk, denoted by [ H k ]m


is the result of the circular convolution of the signal
h[n] with k.
C. Nikou Digital Image Processing (E12)

41

Diagonalization of circulant matrices


(cont.)

[ H k ]m
l =mn

1
=
N

N 1

1
= h [ m n ]N k [ n] =
N
n =0

m ( N 1)

l =m

k ( m l )
N

h [l ]N w

N 1

h [ m n]
n=0

1 k m
= wN
N

k n
N

m ( N 1)

l =m

h [l ]N wNk l

m
1 k m 1
kl
kl
= wN h [l ]N wN + h [l ]N wN
N
l =0
l = m ( N 1)

We will break it into two parts


C. Nikou Digital Image Processing (E12)

42

Diagonalization of circulant matrices


(cont.)

N 1
N 1
1 k m 1
kl
kl
kl
= wN h [l ]N wN + h [l ]N wN h [l ]N wN
N
l =0
l = m +1
l = m ( N 1)

Periodic with respect to N.


N 1
N 1
1 k m N 1
kl
kl
kl
= wN h [l ]N wN + h [l ]N wN h [l ]N wN
N
l =0
l = m +1
l = N + m ( N 1)

N 1
N 1
1 k m N 1
kl
kl
kl
= wN h [l ]N wN + h [l ]N wN h [l ]N wN
N
l =0
l = m +1
l = m +1

C. Nikou Digital Image Processing (E12)

43

Diagonalization of circulant matrices


(cont.)

[ H k ]m

1 k m N 1
kl
= wN h [l ]N wN
N
l =0

= H [k ][ k ]m

DFT of h[n] at k.

This holds for any value of m. Therefore:

H k = H [k ] k
which means that k, for any k, is an eigenvector of
H with corresponding eigenvalue the k-th element
of H[k], the DFT of the signal generating H .
C. Nikou Digital Image Processing (E12)

44

Diagonalization of circulant matrices


(cont.)
The above expression may be written in terms of
the inverse DFT matrix:
1

HA = A
=diag { H [0], H [1],..., H [ N 1]}

or equivalently: = HA 1
Based on this diagonalization, we can prove the
property between circular convolution and DFT.
C. Nikou Digital Image Processing (E12)

45

Diagonalization of circulant matrices


(cont.)

g = Hf g = HA -1 Af

Ag = AHA -1 Af G = F

0
0
G[0] H [0]
F [0]
G[0] 0

H
[1]

0
F
[0]
=

0 H [ N 1] F [ N 1]
G[ N 1] 0
DFT of g[n]

DFT of h [n]

C. Nikou Digital Image Processing (E12)

DFT of f [n]

Diagonalization of doubly block


circulant matrices

46

These properties may be generalized in 2D.


We need to define the Kronecker product:
A

M N

, B

K L

a11B a12 B a1N B


a B a B a B
22
2N

A B = 21

aM 1B aM 2 B aMN B MK NL
C. Nikou Digital Image Processing (E12)

47

Diagonalization of doubly block


circulant matrices (cont.)

The 2D signal f [m,n], 0 m M 1, 0 n N 1,


may be vectorized in lexicographic ordering
(stacking one column after the other) to a
vector:
MN1
f
The DFT of f [m,n], may be obtained in
matrix-vector form:
F = (A A)f
C. Nikou Digital Image Processing (E12)

48

Diagonalization of doubly block


circulant matrices (cont.)
Theorem: The columns of the inverse 2D DFT
matrix
1

(A A)

are eigenvectors of any doubly block circulant


matrix. The corresponding eigenvalues are the 2D
DFT values of the 2D signal generating the doubly
block circulant matrix:

= (A A) H (A A)
Diagonal, containing the 2D DFT
of h[m,n] generating H

Doubly block circulant

C. Nikou Digital Image Processing (E12)

You might also like