121 lines
6.8 KiB
TeX
121 lines
6.8 KiB
TeX
\section{Gaussian Filter Approximation}
|
|
% Basic box filter formula
|
|
% Recursive form
|
|
% Gauss Blur Filter
|
|
% Repetitive Box filter to approx Gauss
|
|
% Simple multipass, n/m approach, extended box filter
|
|
Digital filters are implemented by convolving the input signal with a filter kernel, \ie{} the digital filter's impulse response.
|
|
Consequently, the filter kernel of a Gaussian filter is a Gaussian with finite support \cite{dspGuide1997}.
|
|
Assuming a finite-support Gaussian filter kernel of size $M$ and an input signal $x$, discrete convolution produces the smoothed output signal
|
|
\begin{equation}
|
|
\label{eq:gausFilt}
|
|
(G_{\sigma}*x)(i) = \frac{1}{\sigma\sqrt{2\pi}} \sum_{k=0}^{M-1} x(k) \expp{-\frac{(i-k)^2}{2\sigma^2}} \text{,}
|
|
\end{equation}
|
|
where $\sigma$ is a smoothing parameter called standard deviation.
|
|
|
|
Note that \eqref{eq:bkdeGaus} has the same structure as \eqref{eq:gausFilt}, except the varying notational symbol of the smoothing parameter and the different factor in front of the sum.
|
|
While in both equations the constant factor of the Gaussian is removed from the inner sum, \eqref{eq:bkdeGaus} has an additional normalization factor $W^{-1}$.
|
|
This factor is necessary to ensure that the estimate is a valid density function, \ie{} that it integrates to one.
|
|
Such a restriction is superfluous in the context of digital filters, so the normalization factor is omitted.
|
|
|
|
Computation of a digital filter using the naive implementation of the discrete convolution algorithm yields $\landau{NM}$, where $N$ is again the input size given by 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 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, an 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{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 radius $l\in \N_0$ is given as
|
|
\begin{equation}
|
|
\label{eq:boxFilt}
|
|
(B_L*x)(i) = \sum_{k=0}^{L-1} x(k) B_L(i-k)
|
|
\end{equation}
|
|
where $L=2l+1$ is the width of the filter and
|
|
\begin{equation}
|
|
\label{eq:boxFx}
|
|
B_L(i)=
|
|
\begin{cases}
|
|
L^{-1} & \text{if } -l \le i \le l \\
|
|
0 & \text{else }
|
|
\end{cases}
|
|
\end{equation}
|
|
is the discrete box kernel.
|
|
|
|
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 box filter several times approximately converges to a Gaussian filter.
|
|
In practice three to five iterations are most likely enough to obtain a reasonable close Gaussian approximation \cite{kovesi2010fast}.
|
|
|
|
This allows rapid approximation of the Gaussian filter using iterated 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 box filter is:
|
|
\begin{equation}
|
|
\label{eq:recMovAvg}
|
|
y(i) = y(i-1) + x(i+l) - x(i-l-1)
|
|
\end{equation}
|
|
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.
|
|
The overall algorithm to efficiently compute \eqref{eq:boxFilt} is listed in Algorithm~\ref{alg:naiveboxalgo}.
|
|
|
|
\begin{algorithm}[t]
|
|
\caption{Recursive 1D box filter}
|
|
\label{alg:naiveboxalgo}
|
|
\begin{algorithmic}[1]
|
|
\Statex \textbf{Input:} $f$ defined on $[1,N]$ and box radius $l$
|
|
\Statex \textbf{Output:} $u \gets B_L*f$
|
|
\State $a := \sum_{i=-l}^{l} f(i) $
|
|
\State $u(1) := a/(2l+1)$
|
|
\For{$i=2 \textbf{ to } N$}
|
|
\State $a:= a + f(i+l) - f(i-l-1) $ \Comment{\eqref{eq:recMovAvg}}
|
|
\State $u(i) := a/(2l+1)$
|
|
\EndFor
|
|
\end{algorithmic}
|
|
\end{algorithm}
|
|
|
|
Given a fast approximation scheme, it is necessary to construct a box filter analogous to a given Gaussian filter.
|
|
As seen in \eqref{eq:gausFilt}, the sole 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}
|
|
\Lideal = \sqrt{\frac{12\sigma^2}{n}+1} \quad \text{.}
|
|
\end{equation}
|
|
|
|
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}
|
|
L_1 &=
|
|
\begin{cases}
|
|
\floor{\Lideal} - 1 & \text{if } \floor{\Lideal} \text{ is odd} \\
|
|
\floor{\Lideal} & \text{else }
|
|
\end{cases} \\
|
|
L_2 &= L_1 + 2 \quad \text{.}
|
|
\end{split}
|
|
\end{align}
|
|
|
|
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-nL_1^2-4nL_1-3n}{-4L_1-4} \quad \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 $[-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.
|
|
|
|
|
|
|
|
|