Implementing the 2D discrete convolution operation in an example

In order to understand the mechanism of the discrete convolution operation, let's do a simple intuitive implementation of this concept and apply it to a sample image with different types of kernel. Let's import the required libraries. As we will implement the algorithms in the clearest possible way, we will just use the minimum necessary ones, such as NumPy:

import matplotlib.pyplot as plt
import imageio
import numpy as np

Using the imread method of the imageio package, let's read the image (imported as three equal channels, as it is grayscale). We then slice the first channel, convert it to a floating point, and show it using matplotlib:

arr = imageio.imread("b.bmp") [:,:, ...

Get Machine Learning for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.