Knowing Convolution Basics
Tags: deeplearning, convolutionalneuralnetwork, convolution
Published: 2020-11-21 15:01:07

In this article, we are going to learn about the grayscale image, colour image and the process of convolution.

### **Grayscale image** 

A grayscale image where the image is represented as only the shades of grey. The intensity of the various pixels of the image is denoted using the values from 0 to 255. i.e., from black to white in terms of an 8-bit integer. It uses only one channel.

![grayscale.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605961674942/27LWVNKGa7.png)

### **Colour image**

Coloured images are constructed by combining red, green and blue (RGB) colours in variable proportions. These 3 colours and hence they are called the primary colours. The colour image pixels contain three channels: The R channel, G channel and the B channel, each having its own intensity values ranging from 0 to 255.

![2020-11-18 (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605961674588/SVlAIbZlU.png)


### **What is a convolution** 

Convolution is the process of multiplying each pixel with the corresponding pixel value of the filter and then adding all of the products to get the result. These combinations of result give the output image representation.

Now let us look at an example of convolution.

We pass a 6x6 input through a filter (Here we are using a vertical filter). We get a 4x4 output.

![convolution total operation.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605962078416/cZYoBa6Y8.png)

Now let us look at how each of the entries in the output is obtained.

We place the filter on top of the input starting from the top left corner till we reach the bottom right corner. Then we perform the process of convolution (multiply the corresponding entries and add them together). The obtained result is the corresponding output entry. Here we take stride value as 1. That is we jump 1 step to the right after each calculation. When we reach the column end, we jump 1 row below. This process goes on till we reach the bottom right corner.

**The Convolution operation:** The part of the input to be convolved with the filter in each step is highlighted.

**The 1st output entry:** 
 *1(2)+1(0)+1(-1)+1(1)+1(0)+1(-2)+1(2)+1(0)+1(-1)  
=2-1+1-2+2-1  
=1*

![convolution first entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605962266294/_AUPtryPp.png)

**The 2nd output entry:**
*1(2)+1(0)+0+1(1)+1(0)+0+1(2)+1(0)+0  
=2+0+0+1+0+0+2+0+0  
=5*

![convolution second entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605962279648/Ux0cOTwwK.png)

**The 3rd output entry:**
*1(2)+1(1)+1(2)  
=2+1+2  
=5*

![convolution third entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963459358/Yak8GekXW.png)

**The 4th output entry:**
*1(-1)+1(-2)+1(-1)  
=-1-2-1  
=-4*

![convolution fourth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963470441/JUCq63aCD.png)

*By performing similar calculations;*  
**The 5th output entry=** *1*

![convolution fifth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963491914/cEjdHwmDh.png)

**The 6th output entry=** *5*

![convolution sixth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963505211/XFyO6oVaw.png)

**The 7th output entry=** *5*

![convolution seventh entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963517669/YT3yPw1YE.png)

**The 8th output entry=** *-4*

![convolution eighth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963528120/jGC4z8W1m.png)

**The 9th output entry=** *1*

![convolution ninth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963551172/06hjxaxC-.png)

**The 10th output entry=** *5*

![convolution tenth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963564511/TnMAJeGlO.png)

**The 11th output entry=** *5*

![convolution elelventh entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963575679/dNXf4eANU.png)

**The 12th output entry=** *-4*

![convolution twekth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963585978/N2x3IL2E6.png)

**The 13th output entry=** *1*

![convolution thirteenth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963603555/TyWOtxAaf.png)

**The 14th output entry=** *5*

![convolution fourteenth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963618224/VOWP9gOXD.png)

**The 15th output entry=** *5*

![convolution fifteenth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963640867/EAbEkx6or.png)

**The 16th output entry=** *-4*

![convolution sixteenth entry.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605963658361/IFInBRvYJ.png)

The output we obtained here is of the order 4 while we have given the input of order 6. Hence we can say that some information loss occurs here.

To prevent this loss of information, we use the padding technique, which will be discussed in upcoming posts.

Thank you for reading. If you liked this post please consider sharing.