Commit 3895c9fd authored by Taddeüs Kroes's avatar Taddeüs Kroes

improc ass4: Updated separability section in report.

parent df410367
......@@ -18,29 +18,145 @@
\section{Analytical Local Structure}
\subsection{Derivatives}
\label{sub:derivatives}
We have been given the following function:
$$f(x, y) = A sin(Vx) + B cos(Wy)$$
The partial derivatives $f_x, f_y, f_{xx}, f_{xy}$ and $f_{yy}$ can be derived as follows:
The partial derivatives $f_x, f_y, f_{xx}, f_{xy}$ and $f_{yy}$ can be
derived as follows:
\begin{table}[H]
\begin{tabular}{rl}
$f_x$ & $= A \frac{\delta}{\delta x} sin(Vx) + B \frac{\delta}{\delta x} cos(Wy)$ \\
$f_x$ & $= \frac{\delta f}{\delta x}$ \\
& $= A \frac{\delta}{\delta x} sin(Vx) + B \frac{\delta}{\delta x} cos(Wy)$ \\
& $= A cos(Vx) \cdot V + B \cdot 0$ \\
& $= AV cos(Vx)$ \\
& \\
$f_y$ & $= A \frac{\delta}{\delta y} sin(Vx) + B \frac{\delta}{\delta y} cos(Wy)$ \\
$f_y$ & $= \frac{\delta f}{\delta y}$ \\
& $= A \frac{\delta}{\delta y} sin(Vx) + B \frac{\delta}{\delta y} cos(Wy)$ \\
& $= A \cdot 0 - B sin(Wy) \cdot W$ \\
& $= -BW sin(Wy)$ \\
& \\
$f_{xx}$ & $= AV \frac{\delta}{\delta x} cos(Vx)$ \\
$f_{xx}$ & $= \frac{\delta f_x}{\delta x}$ \\
& $= AV \frac{\delta}{\delta x} cos(Vx)$ \\
& $= -AV^2 sin(Vx)$ \\
& \\
$f_{xy}$ & $= AV \frac{\delta}{\delta y} cos(Vx) = 0$ \\
$f_{xy}$ & $= \frac{\delta f_x}{\delta y} = AV \frac{\delta}{\delta y} cos(Vx) = 0$ \\
& \\
$f_{yy}$ & $= -BW \frac{\delta}{\delta y} sin(Wy)$ \\
$f_{yy}$ & $= \frac{\delta f_y}{\delta y}$ \\
& $= -BW \frac{\delta}{\delta y} sin(Wy)$ \\
& $= -BW^2 cos(Wy)$ \\
\end{tabular}
\end{table}
\pagebreak
\subsection{Plots}
The following plots show $f(x, y)$ and its first and second derivatives. The
image on the left shows $f_x$ and $f_y$. The image on the right shows $f_{xx}$
and $f_{yy}$ in a quiver plot over $f(x, y)$. The arrows point towards the
largest increase of gray value, which means that the derivations in chapter
\ref{sub:derivatives} are correct.
\begin{figure}[H]
\hspace{-2cm}
\includegraphics[scale=.8]{samples.pdf}
\caption{Plots of $f(x, y)$ and its first and second derivatives.}
\end{figure}
\section{Gaussian Convolution}
\subsection{Implementation}
All Gaussian functions are implemented in the file \emph{gauss.py}. The
\texttt{Gauss} function fills a 2D array with the values of the 2D Gaussian
function\footnote{\label{footnote:gaussian-filter}
\url{http://en.wikipedia.org/wiki/Gaussian_filter}}:
$$g_{2D}(x, y) = \frac{1}{2 \pi \sigma^2} e^{-\frac{x^2 + y^2}{2 \sigma^2}}$$
This function converges to zero, but never actually equals zero. The filter's
size is therefore chosen to be $\lceil 6 * \sigma \rceil$ in each direction by
convention (since values for $x,y > 3 * \sigma$ are negligible). Finally,
because the sum of the filter should be equal to 1, it is divided by its own
sum.
The result of the \texttt{Gauss} function is shown in figure
\ref{fig:gauss-diff}. The subplots respectively show the original image, the
Gaussian kernel and the convolved image.
\begin{figure}[H]
\label{fig:gauss-diff}
\hspace{-5cm}
\includegraphics[scale=.6]{gauss_diff_5.pdf}
\caption{The result of \texttt{python gauss.py diff 5}.}
\end{figure}
\subsection{Measuring Performance}
We've timed the runtime of the \texttt{Gauss} function for
$\sigma = 1,2,3,5,7,9,11,15,19$, the results are in figure
\ref{fig:times-2d}. The graph shows a computational complexity of
$\mathcal{O}(\sigma^2)$.
\begin{figure}[H]
\label{fig:times-2d}
\center
\includegraphics[scale=.5]{gauss_times_2d.pdf}
\caption{The result of \texttt{python gauss.py timer 2d 5} (so, each
timing has been repeated 5 times and then averaged).}
\end{figure}
\section{Separable Gaussian Convolution}
\subsection{Implementation}
The \texttt{Gauss1} function uses the 1D Gaussian
function\ref{footnote:gaussian-filter}:
$$g_{1D}(x) = \frac{1}{\sqrt{2 \pi} \cdot \sigma} e^{-\frac{x^2}{2 \sigma^2}}$$
This function returns a 1D array of kernel values, which is used by the
function \texttt{convolve1d}. Using the separability property, the following
code snippets produce the same result:
\begin{verbatim}
W = Gauss1(s)
G = convolve1d(F, W, axis=0, mode='nearest')
G = convolve1d(G, W, axis=1, mode='nearest')
\end{verbatim}
as opposed to:
\begin{verbatim}
G = convolve(F, Gauss(s), mode='nearest')
\end{verbatim}
The timing results of the first code snippet are displayed in figure
\ref{fig:times-1d}. The graphs shows that \texttt{Gauss1} has a computational
complexity of $\mathcal{O}(\sigma)$, which is much faster than the 2D
convolution (certainly for higher scales).
\begin{figure}[H]
\label{fig:times-1d}
\center
\includegraphics[scale=.5]{gauss_times_1d.pdf}
\caption{The result of \texttt{python gauss.py timer 1d 50}.}
\end{figure}
\section{Gaussian Derivatives}
\subsection{Separability}
We can show analytically that all derivatives of the 2D Gaussian function
are separable as well:
\begin{table}[H]
\begin{tabular}{rl}
$ $ & $= $ \\
\end{tabular}
\end{table}
\end{document}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment