 5 of the course Microwave Remote Sensing in Hydrology. Today we shall try to discuss on an inherent characteristic of synthetic aperture radar known as speckle. So, a synthetic aperture radar image can be considered to be a collection of data samples. Now you may ask samples of what? So, samples of amplitude information and phase information at different polarizations. So, we cannot directly equate the pixel in a SAR image that is synthetic aperture radar image to dimensions on the ground. And as mentioned earlier, we have seen that each pixel in a synthetic aperture radar image is represented by a complex number that is described by the amplitude and phase angle. So, firstly let us see how speckle looks like in a synthetic aperture radar imagery. So, the data like what you see on your screen is not easy to work with and SAR imagery can be provided in different formats of which as I mentioned earlier the raw data is not that easy to work with. Nevertheless, all the SAR imagery shall exhibit a characteristic property known as speckle. They say speckle is noise like but not noise. But nevertheless all coherent imaging system like lasers, sonars or ultrasound they shall exhibit this salt and pepper noise that is grainy appearance. Now shown here towards your left side is an image that is unfiltered that is a raw image which contains speckle. So, right now I am not going to specify what is meant by filtering. And shown towards your right side is an image after filtering using a particular filter known as median filter 3 cross 3. So, we will come to what is filter and median filter and 3 cross 3. But I just thought to show you these two images side by side so that you can understand what we are trying to achieve here. So, let us try to start with spatial convolution and its concept. So, you already know how speckle looks like the grainy appearance looks like in a synthetic aperture radar image. So, to decrease the effect of speckle certain de-speckling filters can be applied to an image which has already been subjected to multi-looking at the processing stage. So, by now I am expecting that you know what is multi-looking because we have already covered it as part of a previous tutorial. So, before we understand about filtering first we should know what is spatial convolution. So, a few kernels or convolution mask are being shown here which is having 3 cross 3, 3 rows, 3 columns, 5 cross 5 and 7 cross 7. They are kept intentionally empty but actually the mask will contain some weights, some weights and a spatial filter is a filter for which the value at any location say i, j or x, y will be a function of values located in a particular spatial pattern around the i, j location in the input image. So, let us try to understand how spatial convolution works. So, again I want you to visualize that this empty matrix has values, has numbers they are intentionally left blank for the sake of clarity. So, assume there is a filter which is having 3 rows, 3 columns let it be any filter. So, I am going to call it as 3 cross 3. So, assume this filter 3 cross 3 which has weights which is not empty which has weights are placed at the left most corner of the image. So, a weighted average approach shall be used to calculate the value of the central cell and once the output value from the filter has been calculated the window shall move one column or one pixel to the right and then the operation is going to be repeated again. So, the window shall be moved rightwards and successive output values shall be computed until the right hand edge of the filter window hits the right margin of the image. So, at this point the filter window is moved down one row that is one scan line and back to the left hand margin of the image to repeat the same procedure again. Again the filter window reaches the bottom right hand corner of the input image. So, until that time this procedure is going to be repeated again. So, once again we have a 3 cross 3 filter it can be 5 cross 5 or 7 cross 7 with weights which are placed at the left most corner of the image and using some approach some weighted average approach will come to that later. We alter the central cell of the image and once the output value is calculated this window that is the filter is going to be moved one pixel to the right and then this operation will be repeated till the window hits the margin of the image. So, once it hits the margin of the image the filter window is going to be moved down by one row or one scan line and then back to the left hand margin of the image and this procedure is going to be repeated until the filter window reaches the bottom right hand corner of the image which means until it reaches the bottom right hand corner of the image. Now generally the output image shall contain fewer rows and columns as compared to the unfiltered image because here by now you may have noticed that we are altering the central value but we are not altering the margins of the image. So, typically the size of the output image will not be same as size of the input image and in order to keep the size of input image and output image the same the unfiltered margin corresponding to the top bottom right and left are filled with zeros or we call it as padded with zeros. We will come to that. So for this exercise also we shall be using the LO Spulsar data which you already have downloaded as part of a previous tutorial for the Mumbai region. I am going to show the exercise using the dataset downloaded for the Mumbai region. So, let us start to understand certain different types of filters beginning with median filter. So, as the name suggests instead of calculating the mean the kernel is used to replace the central value with the median values each time and a median filter is actually well known to tackle the salt and pepper noise as it may not improve much the appearance of the image visually but then a median filter also does not alter the final image statistics that is it does not replace the value with a weighted average value it does not alter the final image statistics. It is just going to look at the median inside the kernel and then replace the central value with the median value. So, let us try to understand it in a programming environment. So, as before I have already created a folder of NPTEL tutorials I can open an empty Jupiter notebook and then name it according to the tutorial 5. Let me replace tutorial 5 of the course on microwave remote sensing in hydrology. So, I have created an empty Jupiter notebook. Let us try to define a median filter first. Now as I mentioned earlier for this particular tutorial we are trying to understand speckle in LO spalsar data sets. So, a few of the steps that should be carried out before we actually work with median filters have already been covered as part of an earlier tutorial. So, I am going to refresh your memory now. The first step is to download the data which was covered in tutorial 2 and the second step is to open the LO spalsar data which was again covered in tutorial 2 and the third step is to examine the HH and HV images covered in tutorial 2. Now the initial set of commands have already been showed that is how you design a file path, how you open an image all these have already been covered as part of earlier tutorial. So, here for the sake of saving time I am not going to repeat the same commands again. So, I am going to directly use the existing commands. So, now that we have completed the initial few steps let us try to define a median filter. Now here if you see I have used DEF that is the keyword for defining a function and the function name is followed by parameters which in this case is the data and the kernel underscore size that is you have to input the data and the kernel size. Indexer is nothing but kernel underscore size by 2. Now the symbol for floor division is used here. So, it is just not a single divide but the symbol of floor division is used here. This is very similar to normal division except that it returns the largest possible integer. Moving on I am going to use np.zeros which returns a new array with a given shape and size but which is filled with zeros. So, data.shape within square brackets 0 gives the number of rows in a data that is data is nothing but the image you have entered as input and data.shape within square brackets 1 gives you the number of columns in a data. Now padding shall have rows equal to rows of data plus indexer and padding shall have columns equal to columns of data plus indexer. So, assume that the size of the data that is the input image you are entering is 1000, 800, 1000 rows and 800 columns and assume that you are using a kernel size of 3 that is 3 cross 3. Then indexer will be 1, is not it? So, here to define a median filter I am using for loop and np.median which computes median along the specified axis and it returns median of the array elements. So, what we have done is we have defined a median filter using the DEF that is keyword for defining a function. So, we have defined a function here we are not using any inbuilt library we are defining a function from the scratch so that we understand how a median filter works. So, now we want to visualize the output image and input image side by side. So, let us apply the median filter first using this command. So, I am going to use the input data as sigma h h image and not only that a specific number of rows and columns of sigma h h image are used as input values and the kernel size is kept as 3 that is 3 cross 3. So, median underscore filter the moment I define a function it computes the median and then the output image is stored in medfill. Say I want to visualize how the output looks like I am going to use the plt.subplots function 1,2 that is 1 row 2 columns. So, in 1 row 2 images are going to be displayed side by side and again in figure size 14 units 8 units that that is nothing but some sort of an aspect ratio. So, here I am going to use .imshow function to display an image with color map as gray and as I mentioned earlier I can also name the figures give it titles using title.set underscore text. So, what I am trying to do is I am trying to display the unfiltered image side by side along with an image which has been subjected to median filtering. Similar set of commands I can write for medfill. Medfill is nothing but output image after it has been subjected to median filtering. So, sigma h h image rows from 500 to 1500 and columns from 2200 to 3000 has been subjected to median filter with a kernel size 3 cross 3 and the output is stored in medfill and I am trying to display both the images side by side. So, this is how it is going to look like. I hope you are able to visualize what we achieved by operating with a median filter. Let us try to look at the second type of filter that is mean filter. So, as the name suggests the mean filter reduces the overall variability of the image and it lowers its contrast and this averaging process can be considered as smearing or blurring and those pixels which have values larger than their immediate neighborhood are reduced and those pixels which have values smaller than their immediate neighborhood are respectively increased in values. That is what averaging does is not it? Now, let us see how this can be performed in python. So, the title is we want to understand mean filter which means I have to define a function using as before def that is nothing but keyword for defining a function. So, I am going to name the function as mean underscore filter that takes in two inputs that is data, the input image and the kernel size and I am going to use floor division to get the indexer. As I mentioned earlier floor division very similar to normal division except that it returns the largest possible integer. As the next step I am going to use np dot zeros which returns a new array of a given shape and size but which is filled with zeros. When I use dot shape it gives me the number of rows and columns. So, dot shape within square brackets 0 gives me the number of rows and dot shape within square brackets 1 it gives me the number of columns. So, this data is entered in the zero array created and then I am going to use a for loop for i in range indexer and padding dot shape within square brackets 0 minus indexer plus 1. Similarly, I can write a for loop for j in range indexer comma padding dot shape within square brackets 1 minus indexer plus 1. So, here I am going to use np dot mean function which computes the arithmetic mean along the specified axis. So, basically it returns the average of the array elements. Having said this the downside of mean filter is that it may not be considered optimum because it simply averages the pixels irrespective of their properties within the imaged scene. So, now we have completed defining the mean filter. We have named it mean underscore filter. So, all the operations shown here are very similar except that instead of np dot median we are using np dot mean. So, now let us apply the filter on to the image. So, I am going to use mean underscore filter that is our defined function name and it needs two inputs the data and the kernel size. So, as data I am going to use the sigma h h image not the full image but a certain part of the image with rows 500 to 1500 and columns 2200 to 3000 and the kernel size I am using 3 that is 3 cross 3. So, now what I want to see is I want to visualize the unfiltered image and the image which has been subjected to mean filtering side by side. So, let me re-iterate these commands we are going to use plt dot subplots and dot im show and as before I can name the images by using dot title dot set underscore text. So, the image towards the left I wanted to display the unfiltered image that is the specific sub plot that is sub part of the sigma h h image and towards the right side I want it to display the output image after mean filtering. So, that is why I am entering mean fill and also I am specifying the title as title dot set underscore text as mean filter 3 cross 3. Let me find out where I committed a mistake because it says invalid syntax. There you go I missed a comma. So, now that we have carried out the filtering I want to display the image it is going to be displayed like this towards the left side I have the unfiltered image and towards the right side I have the image after it is being subjected to mean filter with a kernel size of 3 cross 3. So, till now we have seen about the speckle we have seen about mean filter we have seen about median filter. In the next section we will try to understand more about something known as a Gaussian filter. Thank you.