#GaussianFilter #OpenCV #NoiseReduction
0:10 Definition of a Gaussian filter
0.53 Examples of Gaussian filter
1:40 Implementation of Gaussian filter
2:45 Results with different kernel sizes.
3:40 Bilateral Filter
4:13 Working of Bilateral Filter
6:07 Result Comparision.
7:30 Comparision between filters.
Github Code : [ Ссылка ]
In this video we discuss the Image Smoothing technique : Gaussian filter
We go through the basics and implementation of gaussian filter and at the end we will implement a trick to not blur edges because of noise filtering.
Gaussian filter is the most common filter which people use because it is safe to assume noise as gaussian noise. And if we convolute gaussian filter over it. We will see lot of noise reduction.
For this filter we need to know CoVariance in X direction and CoVariance for Y direction.
If you don't have those values we can derive equal covariance with the kernel size.
To use the Guassian filter we need to specify the width and height of the kernel which should be positive and odd. We also should specify the standard deviation in the X and Y directions, sigmaX and sigmaY respectively.
Examples of gaussian kernel of size 3X3 , 5X5 , 7X7 is shown. If you notice these number shows a bell curve where central pixel has highest weight and as we go away the value decreases.
For example central pixel value, 159 now if you go in +ve X or -ve X or in Y direction you will see value reducing just like a bell curve. That means close neighbour pixel values have more effect than farther pixel values unlike mean filter where the weights are same.
If you are new to kernels convolution and padding click on top right corner and view the video on mean filter which covers all these basics. Link : [ Ссылка ]
In the video we take an example of an input image which is very sharp and without noise in order to see effect of our filter. We then generate gaussian noise. We add the noise in our input image.
In order to remove the noise we will use gaussian kernel. Then we pass 3X3 kernel through this image and see that the noise is reduced a bit but edges are also becoming blur.
However if we use a large kernel of size 29 X 29 which reduced the noise but we lost lot of sharpness. Hence, we have a tradeoff between reduction of noise and losing sharpness.
Finally we understand the trick.
Bilateral filter is a gaussian filter in disguise where it reduces gaussian noise and does not blur the edges. cv.bilateralFilter() is highly effective in noise removal while keeping edges sharp. But the operation is slower compared to other filters.This Gaussian filter is a function of space alone, that is, nearby pixels are considered while filtering. It doesn't consider whether pixels have almost the same intensity. It doesn't consider whether a pixel is an edge pixel or not. So it blurs the edges also, which we don't want to do.
Hence to answer why Bilateral filter works? we need to understand why the edges get blur? It is because there is huge intensity difference at an edge and kernel averages it out.
Bilateral filtering also takes a Gaussian filter in space, but one more Gaussian filter which is a function of pixel difference. The Gaussian function of space makes sure that only nearby pixels are considered for blurring, while the Gaussian function of intensity difference makes sure that only those pixels with similar intensities to the central pixel are considered for blurring. So it preserves the edges since pixels at edges will have large intensity variation.
Hence Bilateral Filter working in one sentence is Gaussian filter on space as well pixel value.
The Gaussian function of space makes sure that only nearby pixels are considered for blurring, while the Gaussian function of intensity difference makes sure that only those pixels with similar intensities to the central pixel are considered for blurring.So it preserves the edges. Because we learned that edges have lot of intensity difference.
We then take a look at an example of an image.
In this case, our central pixel value is 20.
We draw a gaussian about central pixel value with defined sigma for color and also position gaussian with defined sigma for space. So high delta in intensity values will have very less effect while convolution.
To use bilateral filter we will need 3 things kernel size , Sigma color , sigma Space. We show the results if we have a 19 X 19 kernel with SigmaColor and SigmaSpace = 300
You see the noise is reduced and edges are also preserved.
Finally a comparison is made in the Output Variation from 19X19 kernel of gaussian filter and bilateral filter.
Ещё видео!