Transfer from http://blog.csdn.net/pi9nc/article/details/26592377

Bilateral filtering

Bilateral filtering is well known, widely used, simple is a filter that takes into account the difference between pixel space and intensity, so it has the characteristic of preserving image edge.

Let's take a look at our familiar Gaussian filters.

where W is the weight, I and J are pixel indexes, and k is the normalized constant. As can be seen in the formula, the weight is only related to the space distance between pixels, regardless of the content of the image, there is the same filtering effect.

Then look at the bilateral filter, it just adds an entry based on the original Gaussian function, as follows

Where I is the intensity value of the pixel, so where the intensity gap is large (edge), the weight will be reduced, the filter effect will be smaller. In general, in the region where the pixel intensity transform is not large, the bilateral filter has the effect of Gaussian filtering, while the gradient can be maintained in places where intensity gradients such as edge of image are high.

Guided filtering

Guided filtering is a filtering technique that has only appeared in the last three years, but not many people know. It is the most similar to the bilateral filter, which is the same with the edge-preserving characteristics. In the definition of guided filtering, a local linear model is used, and the model can be briefly understood

The model argues that the point of a function is linearly related to its neighboring part, and that a complex function can be represented by a number of local linear functions, when the value of a point on the function needs to be asked, the value of all linear functions containing that point is computed and averaged. This model is useful for representing non-analytic functions.

Similarly, we can assume that the image is a two-dimensional function, and cannot write the analytic expression, so we suppose that the output of the function and input in a two-dimensional window satisfies the linear relationship, as follows

where q is the value of the output pixel, I is the value of the input image, I and k are pixel indexes, A and b are the coefficients of the linear function when the center of the window is at K. In fact, the input image is not necessarily the image to be filtered itself, can also be other images as the boot image, which is why it is called the guidance filter. The gradient on both sides of the upper type can be obtained

That is, when the input image I has a gradient, the output Q also has a similar gradient, can now explain why the guided filter has edge-preserving characteristics.

The next step is to find the coefficient of the linear function, that is, the linearity regression, that is, the output value of the desired fitting function and the real value of the difference between P, which is the smallest

Here p can only be filtered images, not like I can be other images. At the same time, the coefficients before a (which are later written as E) are used to prevent the obtained a from being too large, and it is also an important parameter to adjust the filter effect. With the least squares, we can get

Wherein, is I in the window W_k average, is I in the window w_k the variance, is the window w_k the number of pixels, is to filter the image P in the window W_k the mean value.

When calculating the linear coefficients for each window, we can find that a pixel is contained by multiple windows, that is, each pixel is described by multiple linear functions. So, as mentioned earlier, to specifically find the output value of a certain point, you simply need to average all the values of the linear function that contain the points, as follows

Here, W_k is all the window containing the pixel I, and K is its center position.

When the guide filter is used as edge hold filter, often I = p, if e=0, obviously a=1, B=0 is E (A, B) is the minimum value of the solution, from the above can be seen, then the filter does not have any effect, will be input intact output. If e>0, in areas where the pixel strength changes small (or monochrome region), there is a approximation to (or equal to) 0, and B is approximately (or equal to), that is, a weighted mean filter is done, whereas in the area of change, a approximates to 1,b approximately 0, the filtering effect of the image is weak and helps to maintain the edge. and E's role is to define what is the change is big, what is small change. In the case of constant window size, with the increase of e, the filtering effect is more obvious.

In the filtering effect, the guidance filter and the bilateral filter are similar, in some details, the guidance filter is better. The biggest advantage of guided filtering is that you can write algorithms that are independent of the window size of the time complexity (which is intended to be discussed later in the article), so it is more efficient when working with pictures in large windows.

Bilateral filtering and guided filtering