# Deriche filter

## Principle

The Deriche filter is a smoothing filter (low-pass) which was designed to optimally detect, along with a derivation operator, the contours in an image (Canny criteria optimization). Besides, as this filter is very similar to a gaussian filter, but much simpler to implement (based on simple first order IIR filters), it is also much used for general image filtering.

Indeed, contrary to a gaussian filter that is often implemented using a FIR (finite response) filter, and which complexity is directly dependant on the desired filtering level (standard deviation sigma), for a first order IIR, which equation is: `y[n] = a*x[n] + (1-a)*y[n-1]`, the complexity is constant and very limited (2 multiplications per pixel), and the filtering level can be arbitrary modified through the "forget factor" a.

Yet, this filter is not symetrical, which can be a problem while processing images. Fortunately, to make it symetrical, one needs only to apply it a second time in the inverse direction (anti-causal filter). At last, to be even closer to a gaussian filter, this sequence causal + anti-causal filtering is applied twice. Here is what we obtain in terms of 1D impulse responses:

In the end, we need four filtering in the horizontal direction, then four filtering in the vertical direction (the filter is separable), hence a fixed complexity of about 16 multiplications / pixel, and this independantly of the desired filtering level. For comparison, with a gaussian filter, the complexity becomes higher whenever the kernel width is 9 pixels or higher.

## C++ API

``````int DericheBlur(const cv::Mat &I, cv::Mat &O, float gamma)
``````

Where:

• I and O are respectively the input and output images. The type of the pixels can be: CV_32F, CV_8U, CV_16S, with an arbitrary number of channels (colors).
• And gamma is the "forget factor" between 0 (no filtering) et 1 (maximal filtering).

``````int DericheGradient(const cv::Mat &I,