Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

3/14/2011

Digital Image Processing

Filtering in the Frequency Domain


(Circulant Matrices and Convolution)
Christophoros Nikou Niko 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 t

N 1

t1 t2 t( N 1) t0 t1 t2 t1 t2 t1 t0 N N

C. Nikou Digital Image Processing (E12)

3/14/2011

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 t

N 1

t1 t2 t( N 1) t0 t1 t2 t1 t2 t1 t0 N N

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 N 1 c0 c1 C = cN 2 c2 cN 1 c1
C. Nikou Digital Image Processing (E12)

cN 1 c2 c1 c0 N N

3/14/2011

Circulant matrices (cont.)


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

C(m, n) = c( m n ) mod N

c1 c2 c0 c N 1 c0 c1 C = cN 2 c2 cN 1 c1

cN 1 c2 c1 c0 N N

C. Nikou Digital Image Processing (E12)

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)

3/14/2011

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)

3/14/2011

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 1 0 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 f size i NxN.
The two signals may be interchanged.

C. Nikou Digital Image Processing (E12)

3/14/2011

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 1 1 0 H= 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 2 = 1 1 1 0 g = Hf = 0 1 1 2 0
g[n] == { 1, 1, 0}

C. Nikou Digital Image Processing (E12)

3/14/2011

13

Block matrices
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 1 4 1 2 5 3 f [m,n] M1=2, N1=3 m 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)

3/14/2011

15

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 1 4 1 2 5 3 f [m,n] m 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)

16

2D linear convolution using doubly block Toeplitz matrices (cont.)


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

0 0 1 0 1 1 0 1

0 0 H3 = 0 0

0 0 0 0 0 0 0 0

C. Nikou Digital Image Processing (E12)

3/14/2011

17

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 1 4 1 2 5 3 f [m,n] m 1 1 1 -1 h [m,n]
H1 H= H2 H3 H3 H1 H2 126

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]).

C. Nikou Digital Image Processing (E12)

18

2D linear convolution using doubly block Toeplitz matrices (cont.)


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

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

C. Nikou Digital Image Processing (E12)

3/14/2011

19

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 1 4 1 2 5 3 f [m,n]
H1 H g = Hf = 2 H3 2 5 H3 3 H1 1 H2 4 1

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

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 T (2 3 2 3) 1 1 0 1 1 0 3 10 T g = Hf = 0 1 1 0 1 1 1 = 5 = (3 10 5 2) (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)

10

3/14/2011

21

2D linear convolution using doubly block Toeplitz matrices (cont.)


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

1 1 1 -1 h [m,n]

1 5 5 1 3 10 5 2 2 3 -2 3 g [m,n]

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

C. Nikou Digital Image Processing (E12)

22

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 3 4 1 2 f [m,n] M1=2, N1=2 m 1 -1 h [m,n] M2=1, N2=2

Another example

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


C. Nikou Digital Image Processing (E12)

11

3/14/2011

23

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 3 4 1 2 f [m,n] m 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)

24

2D linear convolution using doubly block Toeplitz matrices (cont.)


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 H2 = 0 0 0 0

C. Nikou Digital Image Processing (E12)

12

3/14/2011

25

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 3 4 1 2 f [m,n] m 1 -1 h [m,n]
H H= 1 H 2 H2 H1 64

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]).

C. Nikou Digital Image Processing (E12)

26

2D linear convolution using doubly block Toeplitz matrices (cont.)


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

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

C. Nikou Digital Image Processing (E12)

13

3/14/2011

27

2D linear convolution using doubly block Toeplitz matrices (cont.)


m 3 4 1 2 f [m,n] m 1 -1 h [m,n]

H g = Hf = 1 H 2

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 (3 1 4) 0 0 1 0 3 3 0 0 1 1 4 1 0 0 0 1 4

C. Nikou Digital Image Processing (E12)

14

3/14/2011

29

2D linear convolution using doubly block Toeplitz matrices (cont.)


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

*
n

1 -1 h [m,n]

3 1 4 1 1 -2 g [m,n]

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

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, 1 0 n N 1, 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)

15

3/14/2011

31

2D circular convolution using doubly block circulant matrices (cont.)


H0 H 1 H = H2 HM 1 HM 1 H0 H1 H M 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.)


0] h [ j, N 1] h [ j,1] 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)

16

3/14/2011

33

2D circular convolution using doubly block circulant matrices (cont.)


m m 0 1 0 1 3 -1 1 2 1 f [m,n]


n

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

1 0 1 H0 = 1 1 0 0 1 1

1 0 0 H1 = 0 1 0 0 0 1

0 0 0 H2 = 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


n

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

T (1 2 1) H1 T (1 3 1) H2 T H0 (0 1 0)

C. Nikou Digital Image Processing (E12)

17

3/14/2011

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]


n

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

1 4 -2 3 4 -3 0 2 -1 g [m,n]

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

C. Nikou Digital Image Processing (E12)

18

3/14/2011

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
2 2 n k

wN = e

w =e
nk N

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 matrix vector form:

F = Af
where
f = [ f [0], f [1],..., f [ N 1]] , F = [ F [0], F [1],..., F [ N 1]]
T 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

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

(w ) (w )

C. Nikou Digital Image Processing (E12)

19

3/14/2011

39

Diagonalization of circulant matrices (cont.)


The inverse DFT is then expressed by:

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

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

(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 ) 1 N 1 ( wN ) N 1 N 1 ( wN )
0 N 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.)


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

Let H be a NxN circulant matrix generated by the 1D N-length signal h[n], that is:

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. is the result of the circular convolution of the signal h[n] with k.
C. Nikou Digital Image Processing (E12)

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

20

3/14/2011

41

Diagonalization of circulant matrices (cont.)


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

[ H k ]m
l =mn

h [ m n]
n =0

N 1

k n wN

1 = N

m ( N 1)

l =m

h [l ]N w

k ( m l ) N

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

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)

21

3/14/2011

43

Diagonalization of circulant matrices (cont.)


1 k m N 1 kl wN h [l ]N wN N l =0
DFT of h[n] at k.

[ H k ]m =

= H [k ][ k ]m

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:

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

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

22

3/14/2011

45

Diagonalization of circulant matrices (cont.)


Ag = AHA -1 Af G = F

g = Hf g = HA -1 Af

0 0 G[0] H [0] F [0] G[0] 0 F [0] H [1] 0 = 0 H [ N 1] F [ N 1] G[ N 1] 0


DFT of g[n] DFT of h [n] DFT of f [n]

C. Nikou Digital Image Processing (E12)

46

Diagonalization of doubly block circulant matrices

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 B B B a a a M2 MN MK NL M1


C. Nikou Digital Image Processing (E12)

23

3/14/2011

47

Diagonalization of doubly block circulant matrices (cont.)


may be vectorized in lexicographic ordering (stacking one column after the other) to a vector: f MN 1

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

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)

24

You might also like