Now, that you have understood the basic idea of filters and convolutions, let’s continue our example from the previous page to understand how convolutions are used to **detect features** (such as vertical or horizontal edges) in an image.

This was an example of how the convolution operation (using an appropriate filter) detects certain features in images, such as horizontal or vertical edges.

In the convolution output using the first filter, only the middle two columns are nonzero while the two extreme columns (1 and 4) are zero. This is an example of **vertical edge detection**.

Note that each column of the 4 x 4 output matrix **looks at exactly three columns** of the input image. The values in the four columns represent the amount of change (or gradient) in the intensity of the corresponding columns in the input image along the horizontal direction.

For example, the output is 0 (20 – 20 or 10 – 10) in the columns 1 and 4, denoting that there is no change in intensity in the first three and the last three columns of the input image respectively.

On the other hand, the output is 30 (20 – (-10)) in the columns 2 and 3, indicating that there is a gradient in the intensity of the corresponding columns of the input image.

**Other Filters**

The filter below is used for **horizontal edge detection**. Convince yourself that this filter will be able to detect horizontal edges in an image.

**Convolution Example**

Let’s see one more example of a convolution operation. Consider the image shown below and convolve it with the 3 x 3 filter to produce a 3 x 3 array.

The GIF below demonstrates the convolution operation.

Although we have only seen very simple filters, one can design arbitrarily complex filters for detecting edges and other patterns. For example, the image below shows **the Sobel filter **which can detect both horizontal and vertical edges in complex images.

We have discussed some simple examples of filters and convolutions, and you may have some questions such as ‘can filters have arbitrary sizes’, ‘can any filter convolve any image’, etc. In the next segment, we will be able to answer these questions using the concepts of** stride** and **padding.**

Report an error