<<

MAP 6385 Convolution and Image Processing

1 Convlution

Definition 1. Let z,w l2(R), the set of indexed on Z such that ∈ k=∞ 1/2 z(m)2 < −∞ ! ∞ kX= The convolution z w of z and w is the defined by the equation ∗ k=∞ (z w)(m)= z(k)w(m k) ∗ −∞ − kX= Definition 2. Let f,g L2(R), the set of from R to R satisfying ∈ ∞ 1/2 (f(x))2 dx < −∞ ∞ Z  The convolution f g of f and g is the function defined by the equation ∗ ∞ (f g)(x)= f(t)g(x t) dt ∗ −∞ − Z Theorem 3. Both definitions of convolutions are linear, associative, commutative, and has 2 2 an identity. The identity for l (R) is e1, defined by e1(m)= δm,0, while the identify for L (R) is the “function” δ(x), thought of as a function which is zero for all x = 0, and yet still has 6 area equal to 1. Definition 4. All three definitions of convolution can be extended to two dimensions. In particular, if z(m, n) and w(m, n) represent two dimensional sequences, then z w is deifned by ∗ ∞ ∞ (z w)(m, n)= z(k, l)w(m k, n l) ∗ −∞ −∞ − − kX= l=X Similarly, if f(x, y) and g(x, y) are functions from R2 to R, then we define f g as ∞ ∞ ∗ (f g)(x, y)= f(t, u)g(x t, y u) dtdu ∗ −∞ −∞ − − Z Z And finally, if z(m, n) and w(m, n) are arrays of dimension M N, then we can define convolution as × M N (z w)(m, n)= z(k, l)w(m k + 1, n l + 1) ∗ − − Xk=1 Xl=1 Theorem 5. In higher dimensions, convolution is bilinear, associative, commutative, with identity. 2 Resizing

Definition 6. Define sinc(x) as

sin(πx) if x = 0 sinc(x)= πx 1 if x =6 0  6 Theorem 7. The function sinc(x) has the following useful properties: sinc(x) is even. • ∞ sinc(x) dx = 1 • −∞ sinc(R m) = 0 if m Z 0 , and sinc(0) = 1. • ∈ − { } sinc(x) is real analytic (meaning it has a convergent power series). • sinc(x) sin(kx) = sin(kx) and sinc(x) cos(kx) = cos(kx) for all k Z. • ∗ ∗ ∈ Example 8. Given a sequence z(m), m Z, assume that z(m) = f(m) for some smooth function f(x). Our goal is to reconstruct (or∈ at least approximate) f(x). If we assume that f(x) has a convergent trig series expansion, then we can use the above theorem to say that f(x) = (f sinc)(x) ∞∗ = f(t)sinc(t x) dt −∞ − Z ∞ f(m)sinc(m x) ≈ − m=−∞ X∞ = z(m)sinc(m x) − m=−∞ X Set g(x) equal to the infinite sum, and we have a good approximation for f(x).

Definition 9. In reality, the infinite sum is too difficult to compute. So we will replace sinc(x) with a different function K(x), known as a . This function should have three good properties: The kernel should have compact support, meaning that K(x) = 0 for x outside of a • compact interval [a, b]. Usually, this interval will be of the form [ a,a]. − The integral of the kernel over R should be 1. • The sum • ∞ K(k x) −∞ − kX= should be 1 for all x. In other words, if z(m) is a function, then g(x) should be a constant function. Example 10. Two functions that satisfy this definition are the box function B(x):

1 if 1 x 1 B(x)= 2 2 0 else − ≤ ≤  and the hat function H(x):

1 x if 1 x 1 H(x)= −0 | | else − ≤ ≤  Example 11. Resizing a list. Given a list z(m) of M points, we want to resize it into a list of N points.

(1) Expand z(m) to an infinite list by setting z(m) = z(1) for m < 1 and z(m) = z(M) for m > M (or use z(m) = 0 for m< 1 and m > M) (in reality, you only need to pad as far as necessary for your choice of kernel).

(2) Define g(x)= z(m)K(x m), where K(x) is your kernel of choice. − (3) Define h(x)= Pg(Mx/N).

(4) Define w(k)= h(k) for 1 k N. ≤ ≤ 3 Edge Detection

Definition 12. Define the Gaussian kernel Gσ(x) to be the pdf of the normal distribution with mean 0, standard deviation σ. Specifically:

1 −x2/(2σ2) Gσ(x)= e √2πσ

For the discrete case, let k be a positive integer. Define the sequence Gσ(m) to be

1 −x2/(2σ2) Gσ(m) e if k m k ≈ √2πσ − ≤ ≤

Gσ(m) = 0 else where σ = k/2. The approximation is picked so that Gσ(m) = 1. Example 13. Edge Detection. Given a sequencePz(m), our goal will be to find a new sequence e(m), where e(m) = 1 if we think there is an “edge” on z near m and e(m) = 0 if we think there is not an edge on z near m. We do this by choosing a blurring constant k, a threshold h, and then doing the following:

1 Convolve z with G for some choice of k. Let w = G z. σ σ ∗ 2 Convolve w with D(m), where D( 1) = 1, D(1) = 1, and D(m) = 0 otherwise. Let a = D w. − − ∗ 3 For all m, let e(m) = 1 if a(m) >h, else let e(m) = 0. | | Notes 14. Some observations about the 1-D edge detection: Larger values of k make for a thicker edge. • Larger values of h make it more difficult to qualify as an edge. •

Convolving with Gσ has the effect of blurring the list, and in doing so it makes it • smoother.

Convolving with D is the same as approximating the . • The theory is to smooth out z(m), then take the derivative of the sequence. • Then we mark the points where the derivative is larger, i.e., where there is a substantial change in the sequence.

Because convolution is associative, we could convolve z with (D G ) directly, instead • ∗ σ of doing it in two steps. Definition 15. Let k be a positive integer, and let σ = k/2. Define the discrete two- dimensional Gaussian kernel Gσ(m, n) by

1 −(m2+n2)/(2σ2) Gσ(m, n) e ≈ √2πσ for k m, n k, and 0 elsewhere. The approximation is picked so that G (m, n) = 1. − ≤ ≤ σ Example 16. Edge Detection on an array. Given an array z(m, n),P our P goal will be to find a new array e(m, n), where e(m, n) = 1 if we think there is an “edge” on z near (m, n) and e(m, n) = 0 if we think there is not an edge on z near (m, n). We do this by choosing a blurring constant k, a threshold h, and then doing the following: (1) Convolve z with G for some choice of k. Let w = G z. σ σ ∗

(2) Convolve w with Dx(m, n), where Dx( 1, 0) = 1, Dx(1, 0) = 1, and D(m, n) = 0 otherwise. Let a = D w. − − ∗ (3) Convolve w with D (m, n), where D (0, 1) = 1, D (0, 1) = 1, and D(m, n) = 0 y y − y − otherwise. Let b = D w. ∗ (4) For all (m, n), let e(m, n) = 1 if a(m, n)2 + b(m, n)2 >h, else let e(m, n) = 0. Notes 17. Some observations about the 2-D edge detection. Larger values of k make for a thicker edge. • Larger values of h make it more difficult to qualify as an edge. •

Convolving with Gσ has the effect of blurring the array, and in doing so it makes it • smoother. Convolving with D is the same as approximating the derivative with respect to x. • x Convolving with Dy is the same as approximating the derivative with respect to y. The theory is to smooth out z(m, n), then calculate the magnitude of the gradient of • the resultant array. Then we mark the points where the magnitude is larger, i.e., where there is a substantial change in the array.

Because convolution is associative, we could convolve z with (D G ) and (D G ) • x ∗ σ y ∗ σ directly, instead of doing it in two steps.