Sie sind auf Seite 1von 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

2

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 {

t

n

|

N −≤≤nN

(

1)

1}

T

(,)

mn

=

t

m

n

ttt
t
0
12
(
N
1)
ttt
10
1
T =⎢ t
t
2
2
t
− 1
t
t
tt
210
N − 1

N

×

N

C. Nikou – Digital Image Processing (E12)

3

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

(,)

mn

=

t

m

n

ttt
t
0
12
(
N
1)
ttt
10
1
T =⎢ t
t
2
2
t
− 1
t
t
tt
210
N − 1

N

×

N

C. Nikou – Digital Image Processing (E12)

4

C

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 {

c

n

| 0

n N

1}

(,)

mn

=

c

(

mn

)mod

N

c
cc
c
0
12
N
− 1
c
cc
N
− 1
0
1
C =⎢ c
c
N
− 2
2
c
1
cc
cc
⎦ ⎥
12
N
− 1
0

N

×

N

C. Nikou – Digital Image Processing (E12)

5

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

C

(,)

mn

=

c

(

mn

)mod

N

c
cc
c
0
12
N
− 1
c
cc
N
− 1
0
1
C =⎢ c
c
N
− 2
2
c
1
cc
cc
⎥ ⎦
12
N
− 1
0

N

×

N

C. Nikou – Digital Image Processing (E12)

6

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
7 matrices

f [n] = {1,

2, 2}, hn[ ] =−{1,

1},

N

1

= 3, N

2

= 2

The linear convolution g[n]=f [n]*h [n] will be of length N=N 1 +N 2 -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).

N 1 =3 columns (the length of f [n]).

The two signals may be interchanged.

C. Nikou – Digital Image Processing (E12)

1D linear convolution using Toeplitz
8 matrices (cont.)

f [n] = {1, 2, 2}, hn[ ] =−{1,

1},

N

1

= 3, N

2

= 2

011

100

110

H

=

001

4

× 3

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
9 matrices (cont.)

f [n] = {1, 2, 2}, hn[ ] =−{1,

1},

N

1

= 3, N

g = Hf =

100

110

011

001

⎡⎤ 1

⎢⎥ 1

⎢⎥

⎢⎥ 0

⎥⎣⎦ ⎢⎥

1

⎡⎤

⎢⎥

2

⎢⎥

⎢⎥

2

=

⎣⎦ − 2

2

= 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}, hn[ ] =−{1,

1},

N

1

= 3, N

2

= 2

The circular convolution g[n]=f [n] h [n] will be of length N=max{N 1 , N 2 }=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}, hn[ ] =−{1,

1},

H =

10
−⎤
1
− 110
011 ⎥

3

×

3

N

1

= 3, N

2

= 2

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}, hn[ ] =−{1,

1},

N

1

= 3, N

g = Hf =

1

1

0

0

1

1

− ⎤⎡ ⎤ ⎡− ⎤

⎦ ⎥

11

02 ⎥⎢

⎥⎢

1

1

0

12 ⎦⎣ ⎥⎢ ⎦ ⎥

⎣ ⎢

=

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

2

= 2

C. Nikou – Digital Image Processing (E12)

13

A

=

Block matrices

AA

11

A

12

22

1 N

AA

21

AA

M

1

A

2 N

A

M

2

MN

A ij 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 A ij is also a Toeplitz (circulant) matrix then A is called doubly block-Toeplitz (doubly block-circulant).

C. Nikou – Digital Image Processing (E12)

2D linear convolution using doubly
14 block Toeplitz matrices

m

1

2

4

5

1

3

f [m,n]

n

M 1 =2, N 1 =3

m

1

1

1

-1

h [m,n]

n

M 2 =2, N 2 =2

The result will be of size (M 1 +M 2 -1) x (N 1 +N 2 -1) = 3 x 4

C. Nikou – Digital Image Processing (E12)

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

m

1

2

4

5

1

3

f [m,n]

n

m

1

1

1

-1

h [m,n]

n

At first, h[m,n] is zero-padded to 3 x 4 (the size of the result).

Then, for each row of h[m,n], a Toeplitz matrix with 3 columns (the number of columns of f [m,n]) is constructed.

m

0

1

1

0

1

-1

0

0

0

0

0

0

h[m,n]

C. Nikou – Digital Image Processing (E12)

n

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

m
0
0
0
0
1
1
0
0
1
-1
0
0
• For each row of h[m,n], a
Toeplitz matrix with 3 columns
(the number of columns of f
[m,n]) is constructed.
n
h[m,n]
100 ⎤
100 ⎤
000 ⎤
110
110
000 ⎥
H
=
H
H
1
2
3
⎢ 011 ⎥
= ⎢
011
= ⎢
000
001
001 ⎦
000 ⎦

C. Nikou – Digital Image Processing (E12)

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

m

1

2

4

5

1

3

f [m,n]

n

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

m

1

1

1

-1

h [m,n]

H

HHH

H

H

H

1

2

3

=

3

1

2

⎦ ⎥

12×6

n

C. Nikou – Digital Image Processing (E12)

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

m

1

2

4

5

1

3

f [m,n]

n

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

m

1

1

1

-1

f =

2

⎡⎤

⎢⎥

5

⎢⎥

⎢⎥ ⎡

⎢⎥ ⎢

⎢⎥ ⎣ ⎢

⎢⎥

⎢⎥

⎣⎦

3

1

4

1

=

h [m,n]

(2

(1

5

4

3)

T

1)

T

⎥ ⎦

n

C. Nikou – Digital Image Processing (E12)

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

m

1

2

4

5

1

3

f [m,n]

g = Hf

=

n

H

H

H

m

1

1

1

-1

2

⎡⎤

⎢⎥

5

1 ⎢⎥

⎢⎥

⎢⎥

3 ⎢⎥

⎢⎥

2

⎢⎥

H

H

H

3

1

2

3

1

4

⎣⎦

1

h [m,n]

n

C. Nikou – Digital Image Processing (E12)

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

g = Hf =

100000

⎤ ⎥ ⎢

= ⎢

2

3

2

3

3

10

5

2

1

5

5

1

⎢ −

⎣ ⎢

110000

0

0

11000

0

1

0

0

02 ⎡⎤

⎢⎥

⎢⎥

⎢⎥ 3

⎢⎥

11 ⎢⎥

14 ⎢⎥

⎢⎥

01 ⎣⎦

1

1

0

0

0

1

1

0

0

0

1

1

1

1

0

0

0

1

1

0

05

0

0

0

1

0

0

000

000011

110

000001

⎥ ⎦

=

( 2

(3

(1

3

10

5

2

5

5

T

3)

2)

T

T

1)

C. Nikou – Digital Image Processing (E12)

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

=

m

m

1

2

4

5

1

3

f [m,n]

n

1 5

3

2 3

10

5

5

-2

1

2

3

g [m,n]

n

*

m

 1 1 1 -1

h [m,n]

g =

(2

(3

(1

3

10

5

2

5

5

n

T

3)

2)

T

T

1)

C. Nikou – Digital Image Processing (E12)

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

Another example

m

3 4

1 2

f [m,n]

n

M 1 =2, N 1 =2

m

1

-1

h [m,n]

n

M 2 =1, N 2 =2

The result will be of size (M 1 +M 2 -1) x (N 1 +N 2 -1) = 2 x 3

C. Nikou – Digital Image Processing (E12)

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

m

3 4

1 2

f [m,n]

n

m

1 -1

h [m,n]

n

At first, h[m,n] is zero-padded to 2 x 3 (the size of the result).

Then, for each line of h[m,n], a Toeplitz matrix with 2 columns (the number of columns of f [m,n]) is constructed.

 0 0 0 1 -1 0

h[m,n]

m

C. Nikou – Digital Image Processing (E12)

n

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

For each row of h[m,n], a Toeplitz matrix with 2 columns (the number of columns of f [m,n]) is constructed.

n

m

0

0

0

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

−⎥ ⎦

1

1

H

1

=

⎣ ⎢

0

0

0

0

0

0

⎦ ⎥

= − 1

0

H

2

C. Nikou – Digital Image Processing (E12)

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

m

3 4

1 2

f [m,n]

n

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

H =

 m 1 -1 h [m,n] H 1 H 2 ⎤ H ⎥ ⎦ H 2 6×4 1

n

C. Nikou – Digital Image Processing (E12)

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

m

3 4

1 2

f [m,n]

n

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

m

1

-1

f

=

⎡⎤

⎢⎥

2

⎢⎥

⎢⎥

3

⎢⎥

4

⎣⎦

1

h [m,n]

= ⎢

⎢ ⎣

(1

(3

2)

T

4)

T

⎥ ⎦

n

C. Nikou – Digital Image Processing (E12)

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

m

3 4

1 2

f [m,n]

n

g = Hf

m

1

-1

h [m,n]

⎡⎤

⎢⎥

⎢⎥

H H ⎢⎥

⎢⎥

⎣⎦

1

2

3

4

H

1

2

H

2

1

=

n

C. Nikou – Digital Image Processing (E12)

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

g = Hf =

 1000 − 1 1 0 0 − 1 0 0 0 1 0 0 − 1 0001 −

⎤⎡ 1

1

⎥⎢ ⎥

⎥⎢ ⎥

⎢⎥ − 2

⎢⎥

⎥⎢ ⎥ ⎣

⎥⎢ ⎥

⎥⎢ ⎥

01 ⎡⎤

02 ⎥ ⎢⎥

⎢⎥

⎢⎥

⎢⎥

14 ⎣⎦

(1

== ⎢

03

3

1

(3

⎦⎣ − 4

1

1

T

2)

4)

T ⎥ ⎦

C. Nikou – Digital Image Processing (E12)

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

=

m

m

3 4

1 2

f [m,n]

n

3

1

1

1

4

-2

g [m,n]

n

*

m

1

-1

h [m,n]

g =

(1

(3

n

1

1

2)

T

4)

T

⎦ ⎥

C. Nikou – Digital Image Processing (E12)

2D circular convolution using doubly
30 block circulant matrices

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

with

0 mM≤ − 1, 0 ≤≤nN 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)

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

HHH

0

M

10

H

21

0

12

M

M

1

HHH

H

HHH

HH =⎢

MM

123

−−

M

H

H

H

⎦ ⎥

H

1

2

3

0

Each H j , 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)

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

H

j

h

j

hj

h jN

[

[

,0]

,1]

=

[

,

1]

Each H j , for j=1,

h jN

hj

h jN

[

[

,

,0]

[

,

1]

2]

j

hj

h

[

[

h

[

j

,1]

,2]

,0]

N

×

N

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)

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

m
m
0
0
0
0
1
0
1
3
-1
1
2
1
n
n
f [m,n]
h [m,n]
10
−⎤
1
100 ⎤
000
H
000 ⎥
H = −
110
H
0
10
2 = ⎢
0
1 = ⎢
000 ⎥ ⎦
011
001 ⎥ ⎦
⎣ ⎢

C. Nikou – Digital Image Processing (E12)

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

m

1

1 3

1 2

0

0

-1

1

f [m,n]

n

 m 0 0 0 1 0 0 1 -1 0

h [m,n]

g = Hf

=

HHH

021

H

H

102

H

HHH

210

⎦ ⎥ ⎢ ⎣

(

121 )

(

13

1

)

(

010

)

T

T

T

⎦ ⎥

n

C. Nikou – Digital Image Processing (E12)

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

g = Hf =

10

1000

100

10

1

⎤⎡ 1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥

⎥⎢ ⎦⎣ 0 ⎥ ⎦

⎥⎢

⎥⎢

⎥⎢

⎥⎢

⎥⎢

⎥⎢

⎥⎢

⎥⎢

⎥⎢

1110000

0

2

1

1

3

1

1000000

100

0

00

10

10

1000

111000

10

10000

10

000000

10 ⎥⎢

⎥⎢

0000001111

10

0000000

⎢ −

0

2

⎢ ⎣

1

3

4

3

1

4

2

= ⎢

C. Nikou – Digital Image Processing (E12)

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

=

m

m

 0 1 0 1 3 -1 1 2 1

f [m,n]

1

4

-2

-3

-1

3 4

0 2

g [m,n]

n

n

 m 0 0 0 1 0 0 1 -1 0

g =

h [m,n]

 ( 02 − 1 ) T ( 34 − 3 ) T ( 14 − 2 ) T

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

we

N

=

j

2

π

Ν

nk

⇔=

w

N

e

j

2

π

n

Ν

k

be the DFT basis elements of length N with:

0 kN≤ − 1, 0 ≤≤nN 1,

C. Nikou – Digital Image Processing (E12)

Diagonalization of circulant matrices
38 (cont.)

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

where

f=

[

f

[0],

A

F = Af

f

[1],

,

f

[

N

1]]

T

,

[

F= F

[0],

F

=

(

()

()

012

() () () ()

00

012

11

0

www

N

NN

1

www

N

NN

1

)

012

(

NN

−−

)( )

11

N

www

N

NN

[1],

,

[

FN

(

()

()

0

w

N

1

w

N

N

w

N

1

N

N

1

1

)

N

1

1]]

T

C. Nikou – Digital Image Processing (E12)

Diagonalization of circulant matrices
39 (cont.)

The inverse DFT is then expressed by:

where

A

1

=

1

N

(

A

*

)

T

=

1

N

(

-1

f=A F

()

()

012 00

() () () ()

012 11

0

www

N

NN

1

www

N

NN

1

)

012

(

NN

−−

)( )

11

N

www

N

NN

(

()

()

0

w

N

1

w

N

N

w

N

1

N

N

)

N

1

1

1

*

T

⎠ ⎟

The theorem implies that any circulant matrix has eigenvectors the columns of A -1 .

C. Nikou – Digital Image Processing (E12)

Diagonalization of circulant matrices
40 (cont.)

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

H

[

mn =−h

(,)

(

m

n

)

mod N

]

hm 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.

[

Hα

The m-th element of the vector Hα k , denoted by

is the result of the circular convolution of the signal h[n] with α k .

k

]

C. Nikou – Digital Image Processing (E12)

m

Diagonalization of circulant matrices
41 (cont.)

[

Hα

k

]

m

lmn

= −

=

1 m

N

=

N 1

n = 0

hm

[

n

]

N

[]

α n

k

(

N

1)

hl [ ]

l

=

m

N

kml (

N

w

)

=

=

1

N

N 1

n = 0

1

N

k m

w

N

hm [

m

(

N

1)

n

]

N

hl [ ]

l

=

m

=

1

N

km

w

N

1

lm

(

=− −

N

1)

hl []

N

kl

w

N

m

kl
+
hl []
w
N
N
l
=
0

We will break it into two parts

k n N

w

N

k l

w

N

C. Nikou – Digital Image Processing (E12)

Diagonalization of circulant matrices
42 (cont.)

=

=

1

N

1

1

(

N

k m

N

hl []

k l

N

w

w

+

N

lm

=− −

1)

Periodic with respect to N.

N
1
lNm
=+− −
(
N

1)

hl []

N

kl

w

N

N

w

N

km

N
−−
11
N
k l
∑∑ k l
hl
[]
w
hl []
w
N
N
N
N
l
=
0
l
= m +
1

11

NN

−−

∑∑

hl

[]

N

w

kl

+−

N

l

=

0

l

= m +

1

hl []

N

kl

w

N

=

1

N

km

w

N

⎣ ⎢

l

111

NNN

−−−

hl

[]

N

∑∑∑ kl

w

N

kl

+−

N

w

N

hl

[]

=+

m

l

l

10

=

=+

m

kl

w

N

⎥ ⎦

C. Nikou – Digital Image Processing (E12)

Diagonalization of circulant matrices
43 (cont.)