\section{Matlab Interface User Guide}

If MIA is installed into \tw{<MIA-ROOT>} add \tw{<MIA-ROOT>/lib/mia-2.0/plugins/matlab} to the MATLAB search path. 
 

\subsection{Supported Functions}

All calls to the MIA library are directed through the \miamex function.
The first parameter to \miamex is a command string that describes the requested function, further parameters follow according to the command.
As an example, a random 2D image is filtered by a Gaussian 2D filter of filter parameter 3 wich results in a filter width of 7:

\lstset{language=matlab}
\begin{lstlisting}
image = rand(256, 128) 
filtered_image = miamex('filter2d', 'gauss:w=3',  image) 
\end{lstlisting}

\noindent 
Supported commands are  \tw{debug},  \tw{deform2d}, \tw{deform3d}, \tw{filter2d}, \tw{filter3d}, \tw{reg2d}, \tw{reg3d}. 
For convenience, a set of functions is defined as MATLAB functions:  \tw{miadeform2d}, \tw{miareg2d}, \tw{miadeform3d},  and \tw{miareg3d}. 


\subsection{Image Filters}

\subsubsection*{Set debug level}

\begin{description}
\item [Command:] debug
\item [Description:] set the verbosity of the run algorithm.\footnote{%
	It seems for some reason, on MS Windows this is not output properly. 
}
\item [Parameters:] verbosity: fatal, error, fail, warning, message, (debug)
\item [Example:] Set debug level to 'message'
\begin{lstlisting}
  miamex('debug', 'message')
\end{lstlisting}
\end{description}

\subsubsection*{2D/3D image filters}

\begin{description}
\item [Command:] filter2d, filter 3d
\item [Description:] An 2D/3D image filter as described in section \ref{sec:2dfilters} and \ref{sec:3dfilters}, respectively.
\item [Parameters:] filter, image
\item [Example:] Filtering an 2D image \tw{image} with a median filter of width 3 and store the result in \tw{filtered}.
\begin{lstlisting}
  filtered = miamex('filter2d', 'median:w=3', image)
\end{lstlisting}
\end{description}

\subsubsection*{2D/3D non-rigid image registration}

\begin{description}
\item [Command:] reg2d, reg3d
\item [Convenience:] miareg2d, miareg3d
\item [Description:] An 2D or 3D image registration algorithm, fluid dynamics and elastic
\item [Parameters:] src, ref, method, soriter, cost, epsilon, startsize, niter

\begin{tabular}{ll}
src & source (floating) image \\
ref & reference image \\
soriter & number of iterations for solver \\
cost & cost function \\
epsilon & registration stopping criterion \\
startsize & multigrid start size \\
niter & number of external iterations  \\
\end{tabular}
\item [Example:] running a fluid synamic registration of a pair of 2D images, src and reference, using the sum of 
  squared differences as criterion. The call is executed by using the convenience fucnction
\begin{lstlisting}
deform_field = miareg2d(src, ref, 'fluid', 20, 'ssd', 0.001, 16, 100)
\end{lstlisting}
\end{description}

\subsubsection*{2D/3D image deformation}

\begin{description}
\item [Command:] deform2d, deform3d
\item [Convenience:] miadeform2d, miadeform3d
\item [Description:] An 2D or 3D image deformation, Given a deformation field $\vu$ the deformed image is
   evaulated from the source image $S(\vx)$ according to $D(\vx) := S(\vx - \vu(\vx))$. 
\item [Parameters:] src, field, interp
\item [Returns:] the deformed image

\begin{tabular}{ll}
src & source image  to be deformed \\
field & deformation field $\vu$ \\
interp & interpolator: nn (neares neighbor), tri (bi/tri-linear), bspline3, bspline4, bspline5, omoms3\\
\end{tabular}
\item [Example 1:] deforming a 3d image by using an input field and the tri-linear interpolator
\begin{lstlisting}
deform_image = miamex('deform3d', image3d, field3d, 'tri')
\end{lstlisting}
\item [Example 2:] deforming a 2d image by using an input field and the convenience function
\begin{lstlisting}
deform_image = miadeform2d(image2d, field2d)
\end{lstlisting}
\end{description}





