Image Processing Reference
In-Depth Information
for x
∈
0..rows(pic)-1
for y
∈
0..rows(pic)-1
newpic
y,x
←
zero(pic):=
0
newpic
We shan't bother to display the results of this operator!
The generalised template convolution operator is then:
tm_conv(pic,temp):= conv
←
Set output pic to black
zero(pic)
w floor
cols(temp)
2
Find size of template
for y
∈
w..rows(pic)-w-1
Cover whole picture
for x
∈
w..cols(pic)-w-1
conv
y,x
←
0
Initialise sum
for yy
∈
Cover whole
0..rows(temp)-1
for xx
∈
0..cols(temp)-1
template
pic_y
←
Find x
co-ordinate
y-w+yy
pic_x
←
x-w+xx
Find y co-ordinate
conv
y,x
←
conv
y,x
+
Add product to sum
(
pic
pic_y,pic_x
·temp
yy,xx
)
Return (integer)
floor(conv)
picture
A 3× 3
averaging
(
mean
) operator sums the points in the 3× 3 neighbourhood centred on the
point of interest. This means we can't process a 1 pixel wide picture border so the operator
first sets the whole output picture to black and then replaces points by the average of their
3×
3 neighbourhood. A direct implementation of this process is
ave33(pic):=
newpic
←
Set output picture
zero(pic)
for x
∈
1..rows(pic)-2
to black
for y
∈
1..rows(pic)-2
Address the
whole picture
pic
+pic
+pic
...
y-1,x-1
y-1,x
y-1,x+1
!
+pic
+pic
+pic
...
y,x-1
y+1
y,x+1
Calculate average
newpic
floor
y,x
+pic
+pic
+pic
y+1,x-1
y+1,x
y+1,x+1
9
Output it
newpic
Let's apply the 3
3 averaging operator
smooth:=ave33(eye)