This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Fusion2018/tex/chapters/mvg.tex

110 lines
5.7 KiB
TeX

\section{Moving Average Filter}
% Basic box filter formula
% Recursive form
% Gauss Blur Filter
% Repetitive Box filter to approx Gauss
% Simple multipass, n/m approach, extended box filter
The Gaussian filter is a popular filter to smooth a signal by convoluting an input signal with the Gaussian function
\begin{equation}
\label{eq:gausfx}
g(x) = \frac{1}{\sigma \sqrt{2\pi}} \expp{-\frac{x^2}{2\sigma^2}} \text{,}
\end{equation}
where $\sigma$ is a smoothing parameter called standard deviation.
In the discrete case the Gaussian filter is easily computed with the sliding window algorithm in time domain.
Convolution is separable if the filter kernel is separable, i.e. multidimensional convolution can be computed as individual one-dimensional convolutions with a one-dimensional kernel.
Because of $\operatorname{e}^{x^2+y^2} = \operatorname{e}^{x^2}\cdot\operatorname{e}^{y^2}$ the Gaussian filter is separable and can be easily applied to multi-dimensional signals.
Separability of a filter can also be used to reduce the number of required operations to compute the filter result.
% TODO ähnlichkeit Gauss und KDE -> schneller Gaus = schnelle KDE
Computation of a filter using the a naive implementation of the sliding window algorithm yields $\landau{NK}$, where $N$ is the length of the input signal and $K$ is the size of the filter kernel.
Note that in the case of the Gaussian filter $K$ depends on $\sigma$.
In order to capture all significant values of the Gaussian function the kernel size $K$ must be adopted to the standard deviation of the Gaussian.
Another approach to efficiently compute a filter result is the FFT-convoultion algorithm which is a $\landau{N\log(N)}$ operation.
For large values of $\sigma$ the computation time of the Gaussian filter might be reduced by applying the filter in frequency domain.
Both signals are transformed into frequency domain using the FFT.
The filtered result is equal to the point-wise multiplication of the transformed signals.
In case of the Gaussian filter the Fourier transform of the kernel can be saved, as the Gaussian is a eigenfunction for the Fourier transform.
While the above mentions algorithms poses efficient computations schemes to compute an exact filter result, approximative algorithms can further speed up the computation.
A well-known rapid approximation of the Guassian filter is given by the moving average filter.
\subsection{Moving Average Filter}
The moving average filter is a simplistic filter which takes an input function $x$ and produces a second function $y$.
A single output value is computed by taking the average of a number of values symmetrical around a single point in the input.
The number of values in the average can also be seen as the width $w=2r+1$, where $r$ is the \qq{radius} of the filter.
The computation of an output value using a moving average filter of radius $r$ is defined as
\begin{equation}
\label{eq:symMovAvg}
y[i]=\frac{1}{2r+1} \sum_{j=-r}^{r}x[i+j] \text{.}
\end{equation}
% TODO O(N) complexity
It is well-known that a moving average filter can approximate a Gaussian filter by repetitive recursive computations.
\eqref{eq:symMovAvg} is equal to convolution of the input signal and the rectangular function.
Given by the central theorem of probabilistic repetitive convolution of a rectangular function with itself will yield a Gaussian in the limit.
Filtering a signal with the moving average filter in several passes approximately converges to a Gaussian filter.
In practice three or five iterations are most likely enough to obtain a reasonable close Gaussian approximation.
This allows rapid approximations of the Gaussian filter as the moving average can be computed with a few additions and multiplications.
Opposed to the Gaussian function were exponential functions need to be evaluated for every output value.
As given in \eqref{eq:gausfx} the solely parameter of the Gaussian kernel is the standard deviation $\sigma$.
In contrast the moving average filter is parametrized by its width $w$.
Therefore, in order to approximate the Gaussian filter of a given $\sigma$ a corresponding value of $w$ must be found.
Given $n$ iterations of moving average filters with identical widths the ideal width $\wideal$, as suggested by Wells~\cite{wells1986efficient}, is
\begin{equation}
\label{eq:boxidealwidth}
\wideal = \sqrt{\frac{12\sigma^2}{n}+1} \text{.}
\end{equation}
In general $\wideal$ can be any real number but the moving average filter in \eqref{eq:symMovAvg} is restricted to odd integer values.
Hence the set of possible approximated standard deviations is limited, because the ideal width has to be rounded to the next valid value.
In order to reduce the rounding error Kovesi~\cite{kovesi2010fast} proposes to perform two box filters with different widths
\begin{align}
\label{eq:boxwidthtwo}
\begin{split}
w_l &=
\begin{cases}
\floor{w_{\text{ideal}}} - 1 & \text{if } \floor{w_{\text{ideal}}} \text{ is odd} \\
\floor{w_{\text{ideal}}} & \text{else }
\end{cases} \\
w_u &= w_l + 2 \text{.}
\end{split}
\end{align}
Given $w_l$ and $w_u$ the approximation is done by computing $m$ box filters of width $w_l$ followed by $(n-m)$ box filters of size $w_u$ where $0\le m\le n$.
As all other values are known $m$ can be computed with
\begin{equation}
\label{eq:boxrepeatm}
m=\frac{12\sigma^2-nw_l^2-4nw_l-3n}{-4w_l-4} \text{.}
\end{equation}
The approximated sigma as a function of the integer width has staircase shaped graph.
By reducing the rounding error the step size of the function is reduced.
However, the overall shape will not change.
\etal{Gwosdek}~\cite{gwosdek2011theoretical} proposed an approach which allows to approximate any real-valued value of $\sigma$.
This is achieved by