CV004: Convolution

Introduction

It is different from math. But, it is similar. There is 1-dim convolution, 2-dim convolution, 3-dim convolution and 4-dim convolution. And for image, we use 2-dim convolution. Besides, we don’t need to turn over the kernel.

OK, let’s see a operator, called prewitt operator:

-1 0 1
-1 0 1
-1 0 1

or:

-1 -1 -1
0 0 0
1 1 1

And sobel operator:

-1 0 1
-2 0 2
-1 0 1

or:

-1 -2 -1
0 0 0
1 2 1

What can it do? Actually, it will be the First-order derivative of the array of the image after convolution by operator. Yeah, it is the function of convolution. We can easily get the derivative. And one more thing about the feature of derivative. The first-order derivative will rough the edges. The second-order derivative will detailed and sensitive on noisy, and it also has bilateral effect. Let’s see the operator of second-order derivative, called laplacian operator.

0 1 0
1 -4 1
0 1 0

or(strong):

1 1 1
1 -8 1
1 1 1

And another function of convolution, called rolling average.

Applications

Gaussian Kernel

There is a function, called GaussianBlur in cv2, the first parameter of it is the image, second is the convolution kernel and third is the variance. The value of kernel and variance is bigger, the image will be more foggy.

cv004_1

Let’s see the original image and the convoluted image.

cv004_2

cv004_3

It is not obvious, change a big number of variance(200).

cv004_4

And change the kernel to (11,11):

cv004_5

OK, we can also do it from another way.

There is a function, called getGaussianKernel of cv2. The firstparameter is the kernel and second is variance. And another function, called sepFilter2D. The first is the source of image, second is the depth and third is convolution on X axis, forth is on Y.

And we do the same thing as before, the kernel is 11 and the variance is 200. Let’s see:

cv004_6

They are almost same.


END

Illustrator / Cagy

Text / Cagy

Editor / Cagy

Design / Cagy