Renamed moving average filter to box filter
This commit is contained in:
@@ -20,77 +20,84 @@ Such a restriction is superfluous in the context of digital filters, so the norm
|
||||
|
||||
Computation of a digital filter using the a naive implementation of the discrete convolution algorithm yields $\landau{NM}$, where $N$ is the length of the input signal and $M$ is the size of the filter kernel.
|
||||
In order to capture all significant values of the Gaussian function the kernel size $M$ must be adopted to the standard deviation of the Gaussian.
|
||||
A faster $\landau{N}$ algorithm is given by the well-known approximation scheme based on iterated moving average filters.
|
||||
While reducing the algorithmic complexity this approximation also reduces computational time significantly due to the simplistic computation scheme of the moving average filter.
|
||||
Following that, a implementation of the iterated moving average filter is one of the fastest ways to obtain an approximative Gaussian filtered signal.
|
||||
A faster $\landau{N}$ algorithm is given by the well-known approximation scheme based on iterated box filters.
|
||||
While reducing the algorithmic complexity this approximation also reduces computational time significantly due to the simplistic computation scheme of the box filter.
|
||||
Following that, a implementation of the iterated box filter is one of the fastest ways to obtain an approximative Gaussian filtered signal.
|
||||
% TODO mit einem geringen Fehler
|
||||
% TODO und somit kann der mvg filter auch die BKDE approxen?
|
||||
|
||||
\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 single output value using a moving average filter of radius $r$ is defined as
|
||||
\subsection{Box Filter}
|
||||
The box filter is a simplistic filter defined as convolution of the input signal and the box (or rectangular) function.
|
||||
A discrete box filter of \qq{radius} $l\in N_0$ is given as
|
||||
\begin{equation}
|
||||
\label{eq:symMovAvg}
|
||||
y[i]=\frac{1}{2r+1} \sum_{j=-r}^{r}x[i+j] \text{.}
|
||||
\label{eq:boxFilt}
|
||||
y[n] = \sum_{k=0}^{L-1} x[k] B_L(n-k)
|
||||
\end{equation}
|
||||
where $L=2l+1$ is the width of the filter and
|
||||
\begin{equation}
|
||||
\label{eq:boxFx}
|
||||
B_L(n)=
|
||||
\begin{cases}
|
||||
L^{-1} & \text{if } -l \le n \le l \\
|
||||
0 & \text{else }
|
||||
\end{cases}
|
||||
\end{equation}
|
||||
is the discrete box kernel.
|
||||
|
||||
Such a filter requires clearly $\landau{Nw}$ operations, where $N$ is the signal length.
|
||||
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.
|
||||
Such a filter clearly requires $\landau{NL}$ operations, where $N$ is the input signal length.
|
||||
It is well-known that a box filter can approximate a Gaussian filter by repetitive recursive computations.
|
||||
Given by the central limit theorem of probability, repetitive convolution of a rectangular function with itself eventually yields a Gaussian in the limit.
|
||||
Likewise, filtering a signal with the moving average filter in several passes approximately converges to a Gaussian filter.
|
||||
Likewise, filtering a signal with the box filter several times approximately converges to a Gaussian filter.
|
||||
In practice three or five iterations are most likely enough to obtain a reasonable close Gaussian approximation \cite{kovesi2010fast}.
|
||||
|
||||
This allows rapid approximation of the Gaussian filter using the moving average filter, which only requires a few addition and multiplication operations.
|
||||
This allows rapid approximation of the Gaussian filter using box filter, which only requires a few addition and multiplication operations.
|
||||
Opposed to the Gaussian filter where several evaluations of the exponential function are necessary.
|
||||
The most efficient way to compute a single output value of the moving average is:
|
||||
The most efficient way to compute a single output value of the box filter is:
|
||||
\begin{equation}
|
||||
\label{eq:recMovAvg}
|
||||
y[i] = y[i-1] + x[i+r] - x[i-r-1]
|
||||
\end{equation}
|
||||
This recursive calculation scheme further reduces the time complexity of the moving average filter to $\landau{N}$, by reusing already calculated values.
|
||||
This recursive calculation scheme further reduces the time complexity of the box filter to $\landau{N}$, by reusing already calculated values.
|
||||
Furthermore, only one addition and subtraction is required to calculate a single output value.
|
||||
|
||||
|
||||
Given a fast approximation scheme, it is necessary to construct a box filter analogous to a given Gaussian filter.
|
||||
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
|
||||
As seen in \eqref{eq:gausFilt}, the solely parameter of the Gaussian kernel is the standard deviation $\sigma$.
|
||||
In contrast, the box function \eqref{eq:boxFx} is parametrized by its width $L$.
|
||||
Therefore, in order to approximate the Gaussian filter of a given $\sigma$ a corresponding value of $L$ must be found.
|
||||
Given $n$ iterations of box filters with identical sizes the ideal size $\Lideal$, as suggested by Wells~\cite{wells1986efficient}, is
|
||||
\begin{equation}
|
||||
\label{eq:boxidealwidth}
|
||||
\wideal = \sqrt{\frac{12\sigma^2}{n}+1} \text{.}
|
||||
\Lideal = \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.
|
||||
In general $\Lideal$ can be any real number, but $B_L$ in \eqref{eq:boxFx} is restricted to odd integer values.
|
||||
Hence, the set of possible approximated standard deviations is limited, because the ideal width must 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 &=
|
||||
L_1 &=
|
||||
\begin{cases}
|
||||
\floor{w_{\text{ideal}}} - 1 & \text{if } \floor{w_{\text{ideal}}} \text{ is odd} \\
|
||||
\floor{w_{\text{ideal}}} & \text{else }
|
||||
\floor{\Lideal} - 1 & \text{if } \floor{\Lideal} \text{ is odd} \\
|
||||
\floor{\Lideal} & \text{else }
|
||||
\end{cases} \\
|
||||
w_u &= w_l + 2 \text{.}
|
||||
L_2 &= L_1 + 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$.
|
||||
Given $L_1$ and $L_2$ the approximation is done by computing $m$ box filters of width $L_1$ followed by $(n-m)$ box filters of size $L_2$, 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{.}
|
||||
m=\frac{12\sigma^2-nL_1^2-4nL_1-3n}{-4L_1-4} \text{.}
|
||||
\end{equation}
|
||||
|
||||
The approximated $\sigma$ as a function of the integer width has a 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$.
|
||||
Just like the conventional box filter, the extended version has a uniform value in the range $[-r; r]$, but unlike the conventional the extended box filter has different values at its edges.
|
||||
Just like the conventional box filter, the extended version has a uniform value in the range $[-l; l]$, but unlike the conventional the extended box filter has different values at its edges.
|
||||
This extension introduces only marginal computational overhead over conventional box filtering.
|
||||
|
||||
\commentByToni{Warum benutzen wir den extended box filter nicht? oder tun wir das? Liest sich so, als wäre er der heilige Gral.
|
||||
@@ -99,10 +106,6 @@ Ansonsten: Kapitel find ich gut. Vielleicht kann man hier und da noch paar sätz
|
||||
|
||||
\commentByToni{Aber irgendwie fehlt mir hier noch so ein Absatz oder Kapitel "Zusammenstecken" der Mathematik. Die Usage kommt wieder so Hart. Und nochmal eine kleine Diskussion zum Zusammenstecken. Vielleicht kann man das mit dem 2D verbinden? Weil aktuell haben wir die beiden Verfahren besprochen, aber der eigene Anteil ist irgendwie nicht ersichtlich. Was war jetzt deine tolle Leistung hier? Das muss durch eine gute Diskussion klar werden.}
|
||||
|
||||
\todo{box filter vs moving average filter vs einfahc eine Abkürzung? :D}
|
||||
|
||||
\commentByToni{Kann man eq(12) und eq(9) nicht irgendwie verbinden?}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user