EECE253 07 Convolution
EECE253 07 Convolution
EECE253 07 Convolution
This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Spatial Filtering
Let I and J be images such that J = T[I]. T[] represents a transformation, such that,
J (r , c) = T [ I ](r , c) = f ({ I (r, c) r {r - s,..., r ,...r + s} , c {c - d ,..., c,...c + d } }).
That is, the value of the transformed image, J, at pixel location (r,c) is a function of the values of the original image, I, in a 2s +1 2d +1 rectangular neighborhood centered on pixel location (r,c).
2011-09-29 1999-2011 by Richard Alan Peters II 2
Moving Windows
The value, J(r,c) = T[I](r,c), is a function of a rectangular neighborhood centered on pixel location (r,c) in I. There is a different neighborhood for each pixel location, but if the dimensions of the neighborhood are the same for each location, then transform T is sometimes called a moving window transform.
1999-2011 by Richard Alan Peters II 3
2011-09-29
Moving-Window Transformations
2011-09-29
Moving-Window Transformations
2011-09-29
Moving-Window Transformations
2011-09-29
Moving-Window Transformations
Moving-Window Transformations
Moving-Window Transformations
Moving-Window Transformations
The output of the transform at each pixel is the (weighted) average of the pixels in the neighborhood.
2011-09-29
11
Moving-Window Transformations
2011-09-29
12
J (r , c) = [ I * h ] (r , c) =
- -
I(r - r, c - c)h(r, c) dr d c ,
r =- s c=- d
B ( r - r , c - c) h (r , c)
13
2011-09-29
mask origin
rotate 180
2011-09-29
2011-09-29
17
Another example
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
18
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
19
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
20
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
21
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
22
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
23
original
2011-09-29 1999-2011 by Richard Alan Peters II
3x3 average
24
Location of impulse
The original image has a black impulse at the center and zeros (white) elsewhere.
The weight matrix has a gray L at its left and zeros (white) elsewhere.
The resulting image has a copy of the weight matrix pegged to the impulse location.
2011-09-29
14
25
2011-09-29
26
1.
2.
3.
2011-09-29
27
Shift-Multiply-Add Approach
The image is copied 1 time for each element in the convolution mask. Each copy is shifted relative to the original by the displacement of its associated mask element. Each copy is multiplied by the value of its associated mask element. The set of shifted and multiplied images is summed pixel wise.
2011-09-29
28
Convolution by an Impulse
An impulse is a digital image, that has a single pixel with value 1; all others have value zero. An impulse at location (, ) is represented by:
d ( r - r , c - c) =
1, if r = r and c = c 0, otherwise
If an image is convolved with an impulse of weight w at location (, ), then the image is multiplied by w and shifted in location down by pixels and to the right by pixels.
[I * wd (r - r, c - c)] (r , c) = wI (r - r, c - c).
2011-09-29 1999-2011 by Richard Alan Peters II 29
Convolution by an Impulse
(r 16, c 16)
1 2
d (r - 0, c - 0)
1 2
d (r -16, c -16)
d (r + 16, c + 16)
1 3
d (r - 0, c - 0)
1 3
d (r -16, c -16)
Three copies, two moved, Weights 1/3 one not moved, = averaged.
2011-09-29 1999-2011 by Richard Alan Peters II 32
d (r + 16, c + 16)
1 5
d (r + 16, c -16)
1 5
d (r - 0, c - 0)
1 5
d (r -16, c + 16)
1 5
d (r -16, c -16)
2011-09-29
34
2011-09-29
35
2011-09-29
36
2011-09-29
37
The weight matrix has a gray L at its left and zeros (white) elsewhere.
The resulting image has a copy of the weight matrix pegged to the impulse location.
In the result, the origin of the weight matrix coincides with the original location of the impulse.
38
Each copy of the (entire) image is multiplied by the value of the weight matrix in black square (here, white = 0) before being accumulated (pixelwise) in the padded image
In this image, only the pixel in the center is nonzero so only it shows a result when the image is multiplied by a nonzero value
2011-09-29
39
Each copy of the (entire) image is multiplied by the value of the weight matrix in black square (here, white = 0) before being accumulated (pixelwise) in the padded image
In this image, only the pixel in the center is nonzero so only it shows a result when the image is multiplied by a nonzero value
2011-09-29
40
weight matrix, h
cpad
n m
rpad
R
cpad = rpad = hcorig hrorig floor( floor( = cpad = rpad n m + + /2) /2) 1 1
Image, I
2011-09-29
41
Image I is RxC
C+n-1
A
R+m-1
R n
2011-09-29
42
conv. mask
hcorig hrorig
hcorig+C-1
output image, J
When done, copy the output image from the accumulator starting at (hrorig, hcorig) and ending at (hrorig+R-1, hcorig+C-1)
2011-09-29
hrorig+R-1
C
44
2011-09-29
45
2011-09-29
46
2011-09-29
47
2011-09-29
48
11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 1 11111111111111111 289 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111 11111111111111111
2011-09-29
49
Image
r0
0 -255
Backward Difference
r0
Forward Difference
r0
Sum of Differences
r0
1999-2011 by Richard Alan Peters II
c
50
2011-09-29
-1 2 -1
-1 2 -1
-1 -1 4 -1 -1
2011-09-29
51
2011-09-29
52
1 2 1
2011-09-29
53
[1
2 1]
2011-09-29
54
0 1 0 1 4 1 0 1 0
2011-09-29
55
1 0 0 0 2 0 0 0 1
2011-09-29
56
0 0 1 0 2 0 1 0 0
2011-09-29
57
1 0 1 0 4 0 1 0 1
2011-09-29
58
1 1 1 1 8 1 1 1 1
2011-09-29
59
2011-09-29
60