An image can be seen as a matrix I, where I(x, y) is the brightness of the pixel located at coordinates (x, y). In the Convolutional neural network, the kernel is nothing but a filter
that is used to extract the features from the images.
3. Introduction
Convolutions are mathematical operations between two functions
that create a third function. In image processing, it happens by
going through each pixel to perform a calculation with the pixel and
its neighbours.
In Convolutional neural network, the kernel is nothing but a filter
that is used to extract the features from the images.
A convolution lets you do many things, like calculate derivatives,
detect edges, apply blurs, etc. A very wide variety of things. And all
of this is done with a ”convolution kernel”.
The kernels will define the size of the convolution, the weights
applied to it, and an anchor point usually positioned at the center.
November 22, 2020 3 / 10
4. Types of kernels
Gaussian
K(u) =
1
√
2π
e− 1
2
u2
Logistic
K(u) =
1
eu + 2 + e−u
Sigmoid function
K(u) =
2
π
1
eu + e−u
November 22, 2020 4 / 10
5. Definition
A kernel is a non-negative real-valued integrable function K. For
most applications, it is desirable to define the function to satisfy two
additional requirements:
1. Normalization: ∞
−∞
K(u)du = 1
2. Symmetry: K(−u) = K(u) for all values of u .
November 22, 2020 5 / 10
6. Convolution filters
An image can be seen as a matrix I, where I(x, y) is the brightness
of the pixel located at coordinates (x, y).
A convolution product is computed between the matrix I and a
kernel matrix K which represents the type of filter.
K can be of size 3 × 3 or 5 × 5. The result of this product will be
the new brightness of the pixel (x, y).
I∗K =
I(1, 1) I(1, 2) ... I(1, n)
. . .
. . .
I(m, 1) I(m, 2) ... I(m, n)
∗
K(1, 1) K(1, 2) K(1.3)
K(2, 1) K(2, 2) K(2, 3)
K(3, 1) K(3, 2) K(3, 3)
Where
I ∗ Kx ,y =
1
i=−1
1
j=−1
I(x + i, y + j) ∗ K(i, j)
November 22, 2020 6 / 10
7. Gaussian Kernel
In image processing filters are mainly used to suppress either the
high frequencies in the image, i.e. smoothing the image, or the low
frequencies, i.e. enhancing or detecting edges in the image.
An image can be filtered either in the frequency or in the spatial
domain.
The corresponding process in the spatial domain is to convolve the
input image f(i,j) with the filter function h(i,j). This can be written
as:
g(i, j) = h(i, j) f (i, j)
The discrete convolution can be defined as a ‘shift and multiply’
operation, where we shift the kernel over the image and multiply its
value with the corresponding pixel values of the image. For a square
kernel with size M× M, we can calculate the output image with the
following formula:
November 22, 2020 7 / 10
8. Calculating Gaussian Convolution Kernels
The Gaussian filter uses the Gaussian function in the kernel of the
filter:
G(x, y) =
1
2πσ2
e− x2
+ y2
2σ2
This filter is a weighted filter which gives more importance to the
central pixels. The parameter σ controls the weight given to the
center.
where,
G(x,y) =The variables referenced as x and y relate to pixel
coordinates within an image.
e = represents the value of Euler’s number has been defined as a
mathematical constant equating to 2.718.
σ = represents a threshold or factor value, as specified by the user.
November 22, 2020 8 / 10
9. Continue...
When calculating the kernel elements, the coordinate values
expressed by x and y should reflect the distance in pixels from the
middle pixel.
In order to gain a better grasp on the Gaussian kernel formula we
can implement the formula in steps.
If we were to create a 3×3 kernel and specified a weighting value of
5.5 our calculations can start off as indicated by the following
illustration:
1
2π(5.5)2 e− 12
+12
2(5.5)2
1
2π(5.5)2 e− 02
+12
2(5.5)2
1
2π(5.5)2 e− 12
+12
2(5.5)2
1
2π(5.5)2 e− 12
+02
2(5.5)2
1
2π(5.5)2 e− 02
+02
2(5.5)2
1
2π(5.5)2 e− 12
+02
2(5.5)2
1
2π(5.5)2 e− 12
+12
2(5.5)2
1
2π(5.5)2 e− 02
+12
2(5.5)2
1
2π(5.5)2 e− 12
+12
2(5.5)2
November 22, 2020 9 / 10
10. Continue...
The calculated values of each kernel element:
0.00509 0.00517 0.0521
0.00517 0.00526 0.00517
0.00509 0.00517 0.00509
An important requirement to take note of at this point being that
the sum total of all the elements contained as part of a
kernel/matrix must equate to one.
At this point the sum total of the kernel equates to .046322.
The kernel values should be updated by multiplying each element by
one divided by the current kernel sum.
k =
0.1098 0.1117 0.1098
0.1117 0.1135 0.1117
0.1098 0.1117 0.1098
Now, successfully calculated a 3×3 Gaussian Blur kernel matrix
which implements a weight value of 5.5.
November 22, 2020 10 / 10