Instead of using an all around averaging filter, we may want to filter that both blurs and image and better preserves the edges in it. And for that we use gaussian blur. This is perhaps the most frequently used low-pass filter in computer vision applications. It’s essentially a weighted average that gives the most weight to the center pixel, but also takes into account the surrounding pixels more so depending on how close they are to the center. This is similar to the first edge detection filter we went through, only these components are all positive, normalized, and summed to one. Here, I read in the same image of a brain that you’ve seen before with speckle noise. And we can see that noise better, if we zoom in a little bit. And I’m going to go through applying a Gaussian blur filter to reduce this noise. Before I filter the image, I first have to convert it to grayscale. Then, because this filter is so commonly used, openCV provides a function to use it called Gaussian blur. This function takes in our grayscale image, the size we want our kernel to be, which I’ll put as five by five, which is slightly bigger than our usual three by three. And lastly, our standard deviation which will automatically be calculated if I set this to zero, and you can learn more about this math in text. For now, know that creating a bigger filter will create a slightly bigger blur. We still need the filter it to be of odd dimensions that we can center each pixel of our image in this kernel. Then I’ll plot these images side by side. Here’s our original grayscale image, and next to it is this blurred version. If we zoom in, we can see that the speckle in this original image is significantly reduced in this blurred image. Lastly, I’ll apply a sobel edge detector to both the unblurred grayscale image and the blurred version to compare their performance. Using filter2D, I’m creating both high pass filtered images: One, using our original grayscale and one using our blurred version. And again I’ll plot both side by side. You can see that the non-blurred image is much noisier and the blurred image has more accurate edge detection, especially in the brain tissue region that we care most about. For this and many other images, it’s very common to first pass an image through a small low pass filter like a Gaussian blur to get rid of noise, and then apply a high pass filter for edge detection. So keep this ordering in mind as you filter images.