 Hello, so in the first section of the tutorial 5, we were trying to understand about what is speckle and how to deal with speckle specific to the allospalcer data sets. So we were using the allospalcer data as an example to infer about how mean filter can be applied to reduce speckle and how median filter can be applied on the image to reduce the speckle. Now let us try to understand more about a third kind of filter known as Gaussian filter. So we are all well aware that in the field of statistics, the most important continuous probability distribution is that of the normal distribution or Gaussian distribution which has a bell shaped curve. So the density function of a normal random variable with mean mu and variance sigma square is given with respect to this expression. So here x is the random variable, mu is the mean and sigma square is the variance. Now let us try to understand how to use this to blur an image using the Gaussian distribution. So before I create a Gaussian filter, I need to define a function known as convolution. So before I understand about a Gaussian filter, let me first create from the scratch a function that performs spatial convolution. Now why it is required will be more clear once we move ahead. But for now, I am again going to use the DEF for defining a function termed as convolution that requires two inputs old image and kernel. So the rows of image and columns are of image are read into image underscore H and image underscore W. Similarly, the size of kernel is read into kernel underscore H and kernel underscore W alright. So now let me use the np.pad function which is used to perform padding in NumPy arrays. So this particular function that is np.pad, it returns the padded array of rank equal to the given array. So I am going to type np.pad old image comma going to specify the pad underscore width floor division is used here again because the line of code was lengthy. I am just trying to type in the line below going to specify mode equal to constant and constant underscore values equal to 0, 30. So let me just pull the line to the front so that all the lines of code are easily visible. So what did I do? I used the np.pad which is used to perform padding in the NumPy arrays. Now that I have specified H and W, I can use np.zeros which creates an array with zeros of size as that of image underscore pad. So that is why I have written np.zeros within brackets image underscore pad dot shape. Now to perform the convolution operation I am going to go with for loop. In tutorial 1, we have already covered the basics of what is a for loop. So I am not expanding in detail here. I hope that you are understanding the for loop by now. So once I use for loop I can also try to use the flatten function. Basically flatten function is used to flatten a matrix to one dimension in Python. So let me first finish typing x and then I try to flatten x in one dimension and then I can try to use the sum. That is once we define the list and pass the list as a parameter, I can pass it on as a parameter to the sum function to get the sum of list of items as return. I am going to type if h equal to equal to 0 return image underscore con within square bracket h colon W colon W underscore end W equal to equal to 0 return yes. So in the first tutorial we have also covered the use of for loops as well as return and then finally return image underscore con within square bracket h colon h underscore end and W colon W underscore end. So what we did just now was we have defined a function to perform spatial convolution from the scratch. Now let us try to understand why we did that. Our main aim to understand about convolution was finally we need to create a Gaussian filter. So now once we run the command and make sure that there are no errors, let us try to define a Gaussian blur image function using DEF which takes inputs as image and sigma. So I am going to use image dot from array and then NP dot as array, NP dot as array it converts input into an array and also we have to define the filter size. So once we define the filter size, let us try to create Gaussian filter as a 0 array to start with. That is why I am going to use NP dot 0s and denoting M as filter underscore size floor division 2 and N and I am using a for loop. Now the aim of doing this is that each time when the filter operates it has to compute whatever we are trying to code and it will be saved in the Gaussian underscore filter. So we need the weights of the Gaussian filter and that is why we have written the spatial convolution function before. So let me type the expression that is NP dot exp x square plus y square by 2 into sigma square. This is nothing but the expression that I had showed while explaining about Gaussian distribution. So now I want to enter the values into Gaussian underscore filter for that I will simply use I have already defined x1, I have already defined x2. So I am going to use 1 by x1 into x2. So here NP dot pi P i is how we type the expression for pi. So now let us try to bring everything together. I need I am underscore filtered that is nothing but convolution that is the function we defined in the previous slide image and then Gaussian underscore filter okay. So what we did just now was in the previous slide we tried to write a function that does spatial convolution from the beginning and in this particular slide we wrote a function to estimate Gaussian blur image okay. Now to visualize the image as before I can apply the Gaussian blur image function to the sigma h h image not the complete image but a part of the image and I can also specify the sigma as 3 and as before I can use the same commands to display the image. To visualize the image side by side as a subplot wherein on the left side I have the unfiltered image and on the right side I have the image that has been subjected to Gaussian filter. So here the code that you have just seen it computes the weight each time and then when you use the convolution function spatial convolution is being performed using the weights okay. That is why we have created a zero array to begin with and what is the need for padding. So all these concepts will be covered once you try to understand how to create a Gaussian filter. So what I am typing is how to display the plot side by side using PLT dot subplots using dot I am sure okay keeping color map as gray and adding a title okay. So as before we can visualize what we have just created towards the left side you have the unfiltered image and towards the right side we have the output image after it has been subjected to Gaussian filtering. So say I want to visualize all the three images side by side to understand which gives me better visual clarity whether it is the mean filter, the output after median filter or the output after Gaussian filter. Only a small change needs to be made here let me show you that. So instead of PLT dot subplots 1, 2 I am going to type 1, 4 say that which means in one row you will get all the 4 images side by side okay. The commands are more or less same so let me just copy paste so that it is quicker. So I have defined the first image towards the left it should show the unfiltered image and the next that is AX within square brackets 1 it should show the output after median filtering and AX within square brackets 2 it should show the output after mean filtering. So I am just making those specific changes AX within square brackets 3 that is the figure towards the right most corner that should display the output after Gaussian filtering. Let me try to change the text accordingly and maybe I will try to display the sigma values as well. Let us try to visualize the results yes. So we have the unfiltered image, the output after applying median filter, the output after applying mean filter and the output after applying Gaussian filter. So to summarize in this particular tutorial we learnt about speckle and in particular we dealt with spatial convolution using mean filter, median filter and Gaussian filter. Now speckle filtering can also be carried out using snap toolbox or any other image processing toolboxes but then for better understanding of each step we have learnt how to code the same using Python. And there are many more filters which can be used to tackle speckle in radar imagery. In this tutorial we have covered just three examples however feel free to explore about more filters if interested. I hope you found this tutorial informative. We shall meet during the next lecture. Thank you.