Computer Vision Week 2.2.1
1. Convolution and its usage
2. How to contruct edge dectors and averaging filters using convolution
- Convolutions are a fundamental and powerful operation in signal/image processing.
- Some form is used in almost every computer vision application.
- Convolution has been hypothesised as a good model of low-level biological visual processing.
- Convolutional Neural Networks (CNNs) are a big part of the recen wave of deep learning, and the convolutional part has enabled impressive results on a variety of tasks.
Simple hand-defined convolutional filters can be used to accomplish:
- Edge enhancement/sharpening
- A convolution can be thought of as concurrently applying a local function to parts of the image.
- Unlike the pixelwise operations we saw before, this looks at a group of pixels in a neighbourhood.
- The manner in which this function is applied to the image is sometimes called a sliding window, as the function only sees a small portion of the image at a time.
- Convolutions are trivially parallellised, which is one reason for their continuing success.
This little array is known by various names:
To use it, we must flip it over to make a template:
A = [19 24 22 10 3 20 22 4 19 14]
convolve with template [-1, 1]
# Note that the template is flipped
scipy.signal.convolve(A, [1, -1], mode='valid')
([ 5, -2, -12, -7, 17, 2, -18, 15, -5])
4) Horizontal Differencing
- [-1, +1] gives a first order apporximation of the derivative (rate of change) of the image (in the x-direction) using finite differences.
- i.e. It measures the strength of vertical edges.
- Mathematically, it is approximating the derivative at the point in-between the 2 pixels.
- Templates are not restricted to being 1-dimensional, they can be 2D as well.
- All this menas is that our convolution function operates oen neighbours in both x and y.
(1) Sobel Filter in x-axis
- Provides a mechanism for reducing noise:
from scipy.signal import convolve2d
sobel_x_kernel = [[-1, 0, +1], [-2, 0, +2], [-1, 0, +1]]
sobel_x_img = convolve2d(img_gray, sobel_x_kernel, 'same')
# 'same' refers to the padding