In this exercise we will look at convolution operator. Convolution is a mathematical operation on two functions, with an output of third function which is usually modification of one of the original functions. In image processing convolution can be calculated by equation:
where f is and input image, h is a convolution matrix (mask), and k is the width of the convolution mask. Convolution mask is square matrix with a center, therefore it is usually interpreted as odd size matrix.
In order to understand a convolution operator, lets assume we have a same convolution operator, in a continuous state space and convolution mask is a Dirac delta function. We will now apply operator to both sides of equation, to see what happens.
In general formulation of convolution, we would not be able to go further, as long as the operator O, that we apply to our image is random. However, because we would like to proceed further with image analysis, we have to make assumption, that our operator O is linear operator, and we can insert this into the integral, as long as the integral of any linear combination of functions equals the same linear combination of the integrals of the functions
At this point, we are almost done, because applying a O to a Dirac delta function, is a impulse response of the system. And as long as our O is also shift invariant, we can derive the final form.
Conclusion: convolution says, what a linear and shift invariant operator does.
Convolution is widely used as a process of image filtration with a different convolution mask. We should not forget, that they are applying an impulse response character of the system to image. It is fine to create your own convolution masks, but most of the commonly used masks, are actually derived as a known impulse response in a frequency domain, and then converted into real space domain with a reverse Fourier transform.
For practical implementation, try to use different convolutions masks. Example masks:
Convolution can be roughly transcribed as producing output image by adding each element of the image to its local neighbor pixel values, weighted by the mask. If we look at the operation, it not possible to compute convolution on the image boundary. The size of the boundary is given by the mask size. For mask of size 3 × 3 the border is 1 pixel, for mask of size 5 × 5 the border is 2 pixels.
You can also try to implement different border handling methods:
- Skip borders – Smaller image after processing
- Ignore borders – Same image with original values at border
- Compute borders – Either with padding zeroes to original image – Or with adjustments to convolution mask
Box Blur 9×9 Sobel edge
Convolution using NI-Vision tools