Image Processing Reference

In-Depth Information

Fig. 5.6
Three different kernels

value beneath
f(
2
,
1
)
, etc. The final value which will be written into the output

image as
g(
2
,
2
)
is found as

g(
2
,
2
)

=

h(

−

1
,

−

1
)

·

f(
1
,
1
)

+

h(
0
,

−

1
)

·

f(
2
,
1
)

+

h(
1
,

−

1
)

·

f(
3
,
1
)

+

h(

−

1
,
0
)

·

f(
1
,
2
)

+

h(
0
,
0
)

·

f(
2
,
2
)

+

h(
1
,
0
)

·

f(
3
,
2
)

+
h(
−

1
,
1
)
·
f(
1
,
3
)
+
h(
0
,
1
)
·
f(
2
,
3
)
+
h(
1
,
1
)
·
f(
3
,
3
)

(5.3)

The principle is illustrated in Fig.
5.7
. We say that we correlate the input image

f(x,y)
with the kernel
h(x,y)
and the result is
g(x,y)
. Mathematically this is

expressed as
g(x,y)

=

f(x,y)

◦

h(x,y)
and written as

R

R

g(x,y)
=

h(i, j)
·
f(x
+
i, y
+
j)

(5.4)

j

=−

R

i

=−

R

where
R
is the radius of the kernel.
3
Below, a C-code example of how to implement

correlation is shown:

for

(y =

Radius ;

y <

(M

−

Radius );

y = y +

1)

{

for

(x =

Radius ;

x <

(N

−

Radius );

x = x +

1)

{

temp

=

0;

for

(j =

−

Radius ;

j

<

( Radius

+

1);

j

=

j

+

1)

{

for

(i =

−

Radius ;

i

<

( Radius +1);

i

=

i

+

1)

{

temp

=

temp

+ h ( i , j )

∗

GetPixel ( input , x+i , y+j );

}

3
The reader is encouraged to play around with this equation in order to fully comprehend it.