Diffusion Equations for Medical Images

Abstract: In brain imaging, the image acquisition and processing processes themselves are likely to introduce noise to the images. It is therefore imperative to reduce the noise while preserving the geometric details of the anatomical structures for various applications. Traditionally Gaussian kernel smoothing has been often used in brain image processing and analysis. However, the direct application of Gaussian kernel smoothing tend to cause various numerical issues in irregular domains with boundaries. For example, if one uses large bandwidth in kernel smoothing in a cortical bounded region, the smoothing will blur signals across boundaries. So in kernel smoothing and regression literature, various ad-hoc procedures were introduce to remedy the boundary effect. Diffusion equations have been widely used in brain imaging as a form of noise reduction. The most natural straightforward way to smooth images in irregular domains with boundaries is to formulate the problem as boundary value problems using partial differential equations. Numerous diffusion-based techniques have been developed in image processing. In this paper, we will overview the basics of isotropic diffusion equations and explain how to solve them on regular grids and irregular grids such as graphs.

\section{Diffusion as a Cauchy problem}
\index{diffusion}
\index{diffusion!Cauchy problem}

Consider $\mathcal{M} \in \mathbb{R}^d$ to be a compact
differentiable manifold. Let $L^2(\mathcal{M})$ be the space of square integrable functions
in $\mathcal{M}$ with inner product \begin{eqnarray} \langle g_1, g_2 \rangle =
\int_{\mathcal{M}} g_1(p)g_2(p) \;d\mu(p),\label{eq:inner}\end{eqnarray} where
$\mu$ is the Lebegue measure such that $\mu(\mathcal{M})$ is the
total volume of $\mathcal{M}$. The norm $\| \cdot \|$ is
defined as $$\|g\| = \langle g,g \rangle^{1/2}.$$
The linear partial differential operator $\mathcal{L}$ is {\em
self-adjoint} if
$$\langle g_1, \mathcal{L}g_2 \rangle = \langle
\mathcal{L}g_1, g_2 \rangle$$ for all $g_1, g_2 \in
L^2(\mathcal{M})$. Then the eigenvalues $\lambda_j$ and
eigenfunctions $\psi_j$ of the operator $\mathcal{L}$ are obtained
by solving \begin{eqnarray} \mathcal{L} \psi_j = \lambda_j
\psi_j.\label{eq:eigen}\end{eqnarray}
Often (\ref{eq:eigen}) is written as
\begin{eqnarray*} \mathcal{L} \psi_j = -\lambda_j
\psi_j\end{eqnarray*}
so care should be taken in assigning the sign of eigenvalues.

\begin{theorem}
\label{lem:eigen}
The eigenfunctions $\psi_j$ are orthonormal.
\end{theorem}
{\em Proof.}
Note $\langle \psi_i, \mathcal{L} \psi_j \rangle = \lambda_j \langle \psi_i, \psi_j \rangle$. On the other hand,
$\langle \mathcal{L} \psi_i, \psi_j \rangle = \lambda_i \langle \psi_i, \psi_j \rangle$. Thus
$$ (\lambda_i - \lambda_j )\langle \psi_i, \psi_j \rangle = 0.$$
For any $\lambda_i \neq \lambda_j$, $\langle \psi_i, \psi_j \rangle=0$, orthogonal.
For $\psi_j$ to be orthonormal, we need $\langle \psi_j, \psi_j \rangle =1$. This is simply done by
absorbing the constant multiple into $\psi_j$. Thus, $\{ \psi_j \}$ is orthonormal. $\square$

In fact $\psi_j$ is the basis in $L^2(\mathcal{M})$. Consider 1D eigenfunction problem
$$\frac{\partial^2}{\partial x^2} \psi_j (x) = - \lambda_j \psi_j(x)$$
in interval $[-l, l]$. We can easily check that
$$\psi_{1j} = \cos \big( \frac{j \pi x}{l} \big), \; \psi_{2j} = \sin \big( \frac{j \pi x}{l} \big), \; j = 1,2, \cdots$$
are eigenfunctions corresponding to eigenvalue $\lambda_j = \big( \frac{j \pi }{l} \big)^2$.
Also $\psi_{10} = 1$ is trivial first eigenfunction corresponding to $\lambda_0 =0$.
The multiplicity of eigenfunctions is caused by the symmetric of interval $[-l, l]$. Based on trigonometric  formula, we can show that the eigenfunctions are orthogonal.
\begin{eqnarray*} \int_{-l}^l \psi_{1i}(x) \psi_{1j}(x) \; dx &=& 0 \mbox{ if } i \neq j \\
\int_{-l}^l \psi_{2i}(x) \psi_{2j}(x) \; dx &=& 0 \mbox{ if } i \neq j\\
\int_{-l}^l \psi_{1i}(x) \psi_{2j}(x) \; dx &=& 0 \mbox{ for any } i,j
\end{eqnarray*}
From $\psi_{1j}^2 (x) + \psi_{2j}^2 (x) =1$ and due to symmetry
$$\int_{-l}^l \psi_{1j}^2 (x)  \; dx =  \int_{-l}^l \psi_{2j}^2 (x) \; dx = l.$$
Thus
\begin{eqnarray*}\psi_{10} &=& \frac{1}{\sqrt{2l}}, \\
\psi_{1j} &=& \frac{1}{\sqrt{l}} \cos \big( \frac{j \pi x}{l} \big), \\
\psi_{2j} &=& \frac{1}{\sqrt{l}}\sin \big( \frac{j \pi x}{l} \big), \; j =1, 2, \cdots
\end{eqnarray*}
are orthonormal basis in $[-l,l]$.

Consider a Cauchy problem of the following form:
\begin{eqnarray}
\frac{\partial g}{\partial t}(p,t) +
\mathcal{L}g(p,t) =0 \label{eq:cauchy1}, g(p,t=0) =f(p),\end{eqnarray}
where $t$ is time variable and $p$ is spatial variable.

The initial functional data $f(p)$ can be further
stochastically modeled as
\begin{eqnarray} f(p) = \nu(p) + \epsilon(p),\label{eq:stochastic1}\end{eqnarray} where
$\epsilon$ is a stochastic noise modeled as a zero-mean Gaussian
random field, i.e., $\mathbb{E} \epsilon(p)=0$ at each point $p$ and $\nu$ is the unknown signal to be estiamted. PDE
(\ref{eq:cauchy1}) diffuses noisy initial data $f$ over time and estimate
the unknown signal $\nu$ as a solution. Diffusion time $t$ controls the
amount of smoothing and will be termed as the {\em bandwidth}. The unique solution to
equation (\ref{eq:cauchy1}) is given as follows. This is a heuristic proof and more rigorous proof is given later. \\

\begin{theorem}\label{thm:cauchy} For the self-adjoint linear differential operator
$\mathcal{L}$, the unique solution of the Cauchy problem
\begin{eqnarray}
\frac{\partial g}{\partial t}(p,t) +
\mathcal{L}g(p,t) =0 , g(p,t=0) =f(p) \label{eq:cauchy2}\end{eqnarray}
is given by
\begin{eqnarray} g(p,t) = \sum_{j=0}^{\infty} e^{-\lambda_j t} \langle f, \psi_j
\rangle \psi_j(p).\label{eq:cauchy.solution}\end{eqnarray}
\end{theorem}
{\em Proof.} For each fixed $t$, since $g \in L^2(\mathcal{M})$,
$g$ has expansion \begin{eqnarray} g(p,t) = \sum_{j=0}^{\infty} c_j(t) \psi_j(p)
\label{eq:expansion}.\end{eqnarray} Substitute equation (\ref{eq:expansion})
into (\ref{eq:cauchy2}). Then we obtain \begin{eqnarray} \frac{\partial}{\partial t} c_j(t) +
\lambda_j c_j(t)=0\label{eq:ODE}\end{eqnarray}
for all $j$. The solution of equation
(\ref{eq:ODE}) is given by $$c_j(t) = b_je^{-\lambda_j t}.$$ So we
have solution $$g(p,t) = \sum_{j=0}^{\infty} b_j e^{-\lambda_j t}
\psi_j(p).$$ At $t=0$, we have
$$g(p,0) = \sum_{j=0}^{\infty} b_j \psi_j(p) = f(p).$$
The coefficients $b_j$ must be the Fourier coefficients $\langle
f,\psi_j \rangle$ and they are uniquely determinded. $\square$

\begin{figure}[t]
\centering
\includegraphics[width=1\linewidth]{WFS-gibbs.pdf}
 \caption{Reduction of Gibbs phenomenon in weighted Fourier series (WFS). The figure was generated by Yuan Wang of University of South Carolinia \citep{wang.2018.annals}.}
\label{fig:Lhkernel}
 \end{figure}

The implication of Theorem \ref{thm:cauchy} is obvious. The
solution decreases exponentially as time $t$ increases and smoothes
out high spatial frequency noise much faster than low
frequency noise. This is the basis of many
of PDE-based image smoothing methods. PDE involving self-adjoint linear
partial differential operators such as the Laplace-Beltrami operator
or iterated Laplacian have been widely used in medical image
analysis as a way to smooth either scalar or vector data along
anatomical boundaries \citep{andrade.2001,bulow.2004,chung.2003.ni}. These methods directly solve PDE using standard numerical techniques such as the finite
difference method (FDM) or the finite element method (FEM). The main shortcoming of
solving PDE using FDM or FEM is the numerical instability and the
complexity of setting up the numerical scheme. The analytic approach called weighted Fourier series (WFS) differs from these previous methods in such a way that we only need
to estimate the Fourier coefficients in a hierarchical fashion to solve PDE \citep{chung.2007.tmi}.

\begin{example}Consider 1D differential operator $\mathcal{L} = \frac{\partial^2}{\partial x^2}$. The corresponding Cauchy problem is 1D diffusion equation
$$ \frac{\partial g} {\partial t} (p,t) + \frac{\partial^2 g}{\partial x^2} (p,t) = 0, g(p,t=0)=f(p), p \in [-l,l].$$
Then the solution of this problem is given by Theorem \ref{thm:cauchy}:
$$g(p,t) = a_0 \psi_{10} + \sum_{j=1}^{\infty} a_j e^{-\lambda_j t} \psi_{1j}(p)+ b_j e^{-\lambda_j t}\psi_{2j}(p),$$
where
\begin{eqnarray*} a_0 &=& \frac{1}{\sqrt{2l}} \int_{-l}^l f(p) \; dp, \\
a_j &=& \frac{1}{\sqrt{l}} \int_{-l}^l f(p)  \cos \big( \frac{j \pi x}{l} \big) \; dp, \\
b_j &=& \frac{1}{\sqrt{l}}   \int_{-l}^l f(p)\sin  \big(  \frac{j \pi x}{l} \big) \; dp
\end{eqnarray*}
for $j =1, 2, \cdots.$
\end{example}

\section{Finite difference method}
\index{finite difference}

One way of solving diffusion equations numerically in  to use finite differences. We will discuss how to differentiate images. There are numerous techniques for differentiation proposed in literature. We start with simple example of image differentiation in 2D image slices. Consider image intensity $f(x,y)$ defined on a regular grid, i.e., $(x,y) \in \mathbb{Z}^2$. Assume the pixel size is $\delta x$ and $\delta y$ in $x$- and $y$-directions. The partial derivative along the $x$-direction of image $f$ is approximated by the finite difference:

\begin{eqnarray*} \frac{\partial f}{\partial
x}(x,y) = \frac{f(x + \delta x, y) - f(x, y)}{\delta x}.
\label{eq:diff1}
\end{eqnarray*}
The partial derivative along the $y$-direction of image $f$ is approximated similarly. $\frac{\partial f}{\partial
x}(x,y)$ and $\frac{\partial f}{\partial
y}(x,y)$  are called the {\em first order derivatives}. Then the {\em second order derivatives} are defined by taking the finite difference twice:

\begin{eqnarray*}
\frac{\partial^2 f}{\partial x^2}(x,y) &=&
\Big[ \frac{f(x + \delta x, y) - f(x,y)}{\delta x} -
\frac{f(x, y) - f(x-\delta x,y)}{\delta x}   \Big] /\delta x  \\
&=& \frac{f(x+ \delta x, y) - 2f(x,y) + f(x-\delta x, y)}{\delta x^2}
\label{eq:Lx}
 \end{eqnarray*}

Similarly, we also have
 \begin{eqnarray*}
 \frac{\partial^2 f}{\partial y^2}(x,y) &=& \frac{f(x, y + \delta y) - 2f(x,y) + f(x, y - \delta y)}{\delta x^2}.
\label{eq:Ly}
 \end{eqnarray*}
Other partial derivatives such as $\frac{\partial^2 f}{\partial x \partial y}$ are  computed similarly.

\subsection{1D diffusion by finite difference}

\begin{figure}[t!]
\centering
\includegraphics[width=1\linewidth]{diffusion-1D.pdf}
 \caption{Gaussian kernel smoothing  (solid line) and diffusion smoothing (dotted  line). (a) before diffusion (b) after 0.05 seconds (5 iterations) (c) after 0.25 seconds (25 iterations) (d) after 0.5 seconds (50 iterations).}
\label{fig:diffusion-1Dsmoothing}
 \end{figure}

Let us implement 1D version of diffusion equations (Figure \ref{fig:diffusion-1Dsmoothing}). Suppose we have a smooth function $f(x,t)$ which is a function of position $x \in \mathbb{R}$ and time $t \in \mathbb{R}^+$. 1D isotropic heat equation is then defined as
\begin{eqnarray} \frac{\partial f}{\partial t} = \frac{d^2 f}{d
x^2}
\label{eq:1Ddiffs}
\end{eqnarray}
with initial condition $f(x, t=0) = g(x)$. Differential equation (\ref{eq:1Ddiffs}) is then discretized as
\begin{eqnarray} f(x, t + \delta t) &=&  f(x,t)  + {\delta t} \frac{d^2 f}{d x^2}(x,y).
\label{eq:2Diffs} \end{eqnarray}
With $t_k = k \delta t$ and starting from $t=0$, (\ref{eq:2Diffs}) can be written as
\begin{eqnarray} f(x, t_{k+1}) = f(x, t_k) +
 \delta t \frac{f(x+ \delta x,t_k) - 2f(x,t_k) + f(x-\delta x,t_k)}{\delta x^2}. \label{eq:1diffusionFD}
\end{eqnarray}

The above finite difference gives the solution at time $t_{k+1}$. To obtain the solution at any time, it is necessary to keep iterating many times with
very small $\delta t$. If $\delta t$ is too small, the computation
is slow. If it is too large, the finite difference will diverge. Then the problem is finding the largest $\delta t$ that
grantee the convergence.

 \begin{figure}[t]
\centering
\includegraphics[width=0.8\linewidth]{1Ddiffusion.pdf}
 \caption{Diffusion of simulated data (dotted line) and the ground truth (black line). The both methods using {\tt conv.m} and {\tt toeplitz.m} all converge to the red line.}
\label{fig:1Ddiffusion}
 \end{figure}

Numerically (\ref{eq:1diffusionFD}) is solved in MATLAB follows. We start with generating a step function as the ground truth (black line in Figure \ref{fig:1Ddiffusion}). We then add $N(0,0.5^2)$ noise.

\begin{verbatim}
x=1:1000;
noise=normrnd(0, 0.5, 1,1000);
signal= [zeros(1,300) ones(1,400) zeros(1,300)];
figure; plot(signal, 'k', 'LineWidth',2);
y= signal + noise;
hold on; plot(y, ':k');
\end{verbatim}

The 2nd order finite difference is coded as {\tt L=[1 -2 1]}. Then it is convoluted with 3 consecutive data at a time in the code blow.

\begin{verbatim}
L = [1 -2 1]
g=y;
for i=1:10000
    Lg = conv(g,L,'same');
    g = g+ 0.01*Lg;
end
hold on;plot(g, 'b', 'LineWidth', 2);
\end{verbatim}

Since the Laplacian is a linear operator, the above convolution can be written as the matrix multiplication. Any linear operation can be discretely encoded as matrix multiplication. Here the Laplacian is encoded using a Toeplitz matrix:

\begin{verbatim}
c=zeros(1,1000);
c(1:2)=[-2 1];
r=zeros(1,1000);
r(1:2)=[-2 1];
L = toeplitz(c,r);
\end{verbatim}

The first 5 columns and rows of the Toelitz matrix {\tt L} is given by
\begin{verbatim}
 L(1:5,1:5)
 ans =
     -2     1     0     0     0
      1    -2     1     0     0
      0     1    -2     1     0
      0     0     1    -2     1
      0     0     0     1    -2
\end{verbatim}

The diffusion is solved by sequential summation of matrix multiplications
\begin{verbatim}
g=y';
for i=1:10000
    g = g+ 0.01*L*g;
end
hold on;plot(g, 'g', 'LineWidth', 2);
\end{verbatim}
The first and last rows of the the Toelitz matrix {\tt L} is {\tt [-2 1 0]} and {\tt [0 1 -2]}, which is different from the 2nd order finite difference {\tt [1 -2 1]}. It will not matter since that may be viewed as the discrete Laplacian in the boundary.  The matrix form of Laplacian can be used in conjunction with the recently developed polynomial approximation method for solving heat diffusion on manifolds \citep{huang.2020.TMI}. \\

{\em Discrete maximum principle.} Since the diffusion
smoothing and kernel smoothing are equivalent, The diffused signal
$f(x,t_{k+1})$ must be bounded by the minimum and the maximum of
signal \citep{chung.2003.cvpr}. Let $x_{i-1}, x_i, x_{i+1}$ be some points with gap $\delta x$.

\begin{eqnarray*} f(x_i,t_{k+1}) &=& f(x_i,t_k) + \delta t
\frac{d^2 f}{d x^2}(x_i,t_k)\\
&\leq& \max \big[f(x_{i-1},t_k), f(x_i,t_k),f(x_{i+1},t_k)
\big].\end{eqnarray*}
Similarly, we can bound it below. Thus, the time step should be bounded by

$$\delta t \leq \max \Big[ \Big|\frac{f(x_{i-1},t_j) - f(x_i,t_j)}
{\frac{d^2 f}{d
x^2}}\Big|,\Big|\frac{f(x_{i+1},t_j)-f(x_i,t_j)}{\frac{d^2
f}{d x^2}}\Big|\Big].$$

\subsection{Diffusion in $n$-dimensional grid}
\index{diffusion}

In 2D,  let $(x_i,y_i)$ be pixels around $(x,y)$ including $(x,y)$ itself.
Then using the 4-neighbor scheme, Laplcian of $f(x,y)$ can be written as
$$\Delta f(x,y) = \sum_{i,j} w_{ij}f(x_i,y_i),$$
where the Laplacian matrix is  given by
$$(w_{ij}) = \left(%
\begin{array}{ccc}
  0 & 1 & 0 \\
  1 & -4 & 1 \\
  0 & 1 & 0 \\
\end{array}%
\right).
$$
Note that $\sum_{ij} w_{ij}=1$.

Extending it further, consider $n$D. Let $x=(x_1, x_2, \cdots, x_n)$ be the coordinates in $\mathbb{R}^n$.
Laplacian $\Delta$ in $\mathbb{R}^n$ is defined as
$$\Delta f = \frac{\partial^2 f}{\partial x_1^2} + \cdots + \frac{\partial^2 f}{\partial x_n^2}.$$
Assume we have a $n$-dimensional hyper-cube grid of size is 1. Then we have
\begin{eqnarray*}   \Delta f(x) &=& f(x_1 \pm 1,\cdots, x_n)  + \cdots + f(x_1, \cdots, x_n \pm 1)  \\
&&- 2n f(x,y).
\end{eqnarray*}
This uses $2n$ closest neighbors of voxel $x$  to approximate the Laplacian.

It is also possible to incorporate $2^n$ corners $(x_1 \pm 1, \cdots, x_n \pm 1)$ along with the $2n$ closest neighbors for a better approximation of the Laplacian. In particular in 2D,  we can obtain a more accurate finite difference formula for 8-neighbor Laplacian:

$$(w_{ij}) = \frac{1}{9}\left(%
\begin{array}{ccc}
  1 & 1 & 1 \\
  1 & -8 & 1 \\
  1 & 1 & 1 \\
\end{array}%
\right).$$

Based on the estimation Laplacian on discrete grid, diffusion equation
\begin{eqnarray*} \frac{\partial f}{\partial t} = \Delta f
\end{eqnarray*}
is discretized as
\begin{eqnarray} f(x, t_{k+1}) = f(x, t_k) + \delta t \sum_{i,j} w_{ij}f(x_i, y_i). \label{eq:1Dfinite}
\end{eqnarray}
with $t_k = k \delta t$ and starting from $t_1=0$. From (\ref{eq:1Dfinite}), we can see that the diffusion equation is solved by iteratively applying
convolution with weights $w_{ij}$. In fact, it can be shown that the solution of diffusion is given by kernel smoothing.

\section{Laplacian on planner graphs}
\index{Laplacian}
\index{Laplacian!planar graphs}

In a previous section, we showed
how to estimate the Laplacian in a regular grid. Now we
show how to estimate Laplacian in irregular grid such as graphs and polygonal
surfaces in $\mathbb{R}^2$. The question is how one estimate Laplacian
or any other differential operators on a graph.
Assume we have observations $Y_i$ at each point $p_i$, which is
assumed to follow additive model
$$Y_i = \mu(p_i) + \epsilon(p_i), \;
p_i \in \mathbb{R}^2$$
where $\mu$ is a smooth continuous function
and $\epsilon$ is a zero mean Gaussian random field. We want to
estimate at some node $p_i$ on a graph:
$$\Delta \mu (p_0)= \frac{\partial^2 \mu}{\partial x^2}\Big|_{p_0} +
\frac{\partial^2 \mu}{\partial y^2}\Big|_{p_0}.$$ Unfortunately,
the geometry of the graph forbid direct application of
finite difference scheme. To answer this problem, one requires the finite element method (FEM) \citep{chung.2001.thesis}. However, we can use  a more elementary technique called {\em polynomial regression}.

Let $p_i = (x_i,y_i)$ be
the coordinates of the vertices of the graph or polygonal surface.
Let $p_i$ be the neighboring vertices of $p_0$. We estimate the Laplacian
at $p_0$ by fitting a quadratic polynomial of the form
 \begin{eqnarray} \mu(u,v) =\beta_0 + \beta_1u + \beta_2v + \beta_3u^2 +
\beta_4uv + \beta_5v^2.\label{eq:quadratic} \end{eqnarray}
We are basically assuming the unknown signal $\mu$ to be the quadratic form (\ref{eq:quadratic}).
Then the parameters $\beta_i$ are estimated by solving the normal
equation:
\begin{eqnarray} Y_i =\beta_0 + \beta_1x_i + \beta_2y_i +
\beta_3x_i^2 + \beta_4x_iy_i + \beta_5y_i^2\end{eqnarray}
for all $p_i$ that is neighboring $p_0$. For simplicity, we may assume $p_0$ is translated to the origin, i.e.,
$x_0=0, y_0 =0$.

Let $Y=(Y_1,\cdots,Y_m)^\top$, $\beta = (\beta_0,\cdots,\beta_5)^\top$ and
design matrix
$$\mathbb{X}= \begin{pmatrix}
1& x_1 & y_1 & x_1^2 & x_1y_1 & y_1^2\\
1& x_2 & y_2 & x_2^2 & x_2y_2 & y_2^2\\
  \hdotsfor[2]{6} \\
1&   x_m & y_m & x_m^2 & x_my_m & y_m^2
\end{pmatrix}.$$
Then we have the following matrix equation
$$Y =\mathbb{X}\beta.$$ The unknown coefficients vector $\beta$ is
estimated by the usual least-squares method:
$$\widehat \beta = (\widehat\beta_0,\dots,\widehat \beta_5)^\top
=(\mathbb{X}^\top \mathbb{X})^{-}\mathbb{X}^\top Y,$$ where $^-$ denotes
generalized inverse, which can be obtained through the singular
value decomposition (SVD). Note that $\mathbb{X}^\top\mathbb{X}$ is
nonsingular if $m <6$. In Matlab, {\tt pinv} can be used to compute the generalized inverse, which is often called the {\em pseudo inverse}.\\

The generalized inverse often used is that of Moore-Penrose.
It is usually defined as matrix $\mathbb{X}$ satisfying four conditions
$$\mathbb{X}\mathbb{X}^{-}\mathbb{X}=\mathbb{X}, \; \mathbb{X}^{-}\mathbb{X}\mathbb{X}^{-}
 = \mathbb{X}^{-},$$
$$(\mathbb{X}\mathbb{X}^{-})^\top=\mathbb{X}\mathbb{X}^{-}, \; (\mathbb{X}^{-}\mathbb{X})^\top=
\mathbb{X}^{-}\mathbb{X}.$$
Let $\mathbb{X}$ be $m \times p$ matrix with $m \geq p$. Then SVD
of $\mathbb{X}$ is
$$\mathbb{X}=UDV^\top,$$
where $U_{m \times p}$ has orthonormal columns, $V_{p \times p}$ is orthogonal, and
$D_{p \times p}=Diag(d_1,\cdots,d_p)$ is diagonal with non-negative elements
and . Let
$$D^{-}=Diag(d_1^{-},\cdots,d_p^{-}),$$
where $d_i^{-} = 1/d_i$ if $d_i
\neq 0$ and $d_i^{-} = 0$ if $d_i=0$. Then it can be shown that
the Moore-Penrose generalized inverse is given by
$$\mathbb{X}^{-}=VD^{-}U^\top.$$

Once we estimated the parameter vector $\beta$,  the Laplacian of is
$$\Delta \mu (p_0)= 2\widehat \beta_3 + 2\widehat
\beta_5.$$

\section{Graph Laplacian}
\index{graph!Laplacian}

Now we generalize volumetric Laplacian in previous sections to graphs. Let $G = (V,E)$ be a graph with node set $V$ and edge set $E$. We will simply index the node set as $V = \{1,2 ,\cdots, p\}$. If two nodes $i$ and $j$ form an edge, we denote it as $i \sim j$. Let $W=(w_{ij})$ be the edge wight. The adjacency matrix of $G$ is often used as the edge weight. Various forms of graph Laplacian have been proposed \citep{chung.1997} but the most often used standard form $L=(l_{ij})$ is given by
$$l_{ij} =\left(
\begin{array}{cc}
  -w_{ij}, &  i \sim j\\
  \sum_{i \neq j} w_{ij}, &  i = j \\
  0, & \mbox{ otherwise}
\end{array}\right .$$
Often it is defined with the sign reversed such that
$$l_{ij} =\left(
\begin{array}{cc}
  w_{ij}, &  i \sim j\\
  -\sum_{i \neq j} w_{ij}, &  i = j \\
  0, & \mbox{ otherwise}
\end{array}\right .$$

The graph Laplacian $L$ can then be written as $$L = D- W,$$ where $D=(d_{ij})$ is the diagonal matrix with $d_{ii} = \sum_{j =1}^n w_{ij}$.
Here, we will simply use the adjacency matrix so that the edge weights $w_{ij}$ are either 0 or 1. In Matlab, Laplacian {\tt L} is simply computed from the adjacency matrix {\tt adj}:

\begin{verbatim}
n=size(adj,1);
adjsparse = sparse(n,n);
adjsparse(find(adj))=1;
L=sparse(n,n);
GL = inline('diag(sum(W))-W');
L = GL(adjsparse);
\end{verbatim}

We use the sparse matrix format to reduce the memory burden for large-scale computation.

\begin{figure}[t]
\centering
\includegraphics[width=1\linewidth]{kernel-lung.pdf}
\caption{A. Part of lung blood vessel obtained from CT. B. Adjacency matrix obtained from 4-neighbor connectivity. C. Laplace matrix obtained from the adjacency matrix.}
\label{fig:Laplacian-adj}
\end{figure}

\begin{theorem} Graph Laplacian $L$ is nonnegative definite.
\end{theorem}
The proof is based on factoring Laplacian $L$ using incidence matrix $\nabla$ such that
$L = \nabla^{\top} \nabla$. Such factorization always yields nonnegative definite matrices.
Very often $L$ is nonnegative definite in practice if it is too sparse (Figure \ref{fig:Laplacian-adj}).

\begin{theorem}For graph Laplacian $L$, $L + \alpha I$ is positive definite for any $\alpha>0$.
\end{theorem}
{\em Proof.} Since $L$ is nonnegative definite, we have
$$ x^{\top} L x \geq 0.$$
Then it follows that
$$ x^{\top} (L + \alpha I) x =  x^{\top} L x + \alpha x^{\top} x > 0$$
for any $\alpha >0$ and $x \neq 0$. $\square$

\begin{figure}[t]
\centering
\includegraphics[width=0.8\linewidth]{diffusion-basis.pdf}
\caption{Top: First few eigenvectors of the Laplacian in a L-shaped domain. Botom: Heat kernel with bandwidths $\sigma =0.01, 0.1$. We have used degree 70 expansions but the shape is almost identical if we use higher degree expansions. The heat kernel is a probability distribution that follows the shape of the L-shaped domain.}
\label{fig:Lshape-basis}
 \end{figure}

Unlike the continuous Laplace-Beltrami operators that may have possibly infinite number of eigenfunctions, we have up to $p$ number of eigenvectors $\psi_1, \psi_2, \cdots, \psi_p$ satisfying
\begin{eqnarray} L \psi_j = \lambda_j \psi_j \label{eq:graph-eigen} \end{eqnarray}
with (Figure \ref{fig:Lshape-basis})
$$0 = \lambda_1 < \lambda_2 \leq \cdots \leq \lambda_p.$$
The eigenvectors are orthonormal, i.e.,
$$\psi_i^\mathsf{T} \psi_j  = \delta_{ij},$$
the Kroneker's delta. The first eigenvector is trivially given as
$\psi_1 = {\bf 1}/\sqrt{p}$ with ${\bf 1} = (1, 1, \cdots, 1)^\mathsf{T}.$

All other higher order eigenvalues and eigenvectors are unknown analytically and have to be computed numerically (Figure \ref{fig:Lshape-basis}). Using the eigenvalues and eigenvectors, the graph Laplacian can be decomposed spectrally. From (\ref{eq:graph-eigen}),
\begin{eqnarray} L \Psi = \Psi \Lambda, \label{eq:graph-psi}\end{eqnarray}
where  $\Psi = [\psi_1, \cdots, \psi_p]$ and $\Lambda$ is the diagonal matrix with entries  $\lambda_1, \cdots, \lambda_p$.
Since $\Psi$ is an orthogonal matrix,
$$\Psi \Psi^\mathsf{T} = \Psi^\mathsf{T}\Psi = \sum_{j=1}^p \psi_j \psi_j^\mathsf{T} = I_p,$$ the identify matrix of size $p$. Then (\ref{eq:graph-psi}) is written as
$$L  = \Psi \Lambda \Psi^\mathsf{T} = \sum_{j=1}^p \lambda_j \psi_j \psi_j^\mathsf{T}.$$
This is the restatement of the singular value decomposition (SVD) for Laplacian.

For measurement  vector $f = (f_1, \cdots, f_p)^\mathsf{T}$ observed at the $p$ nodes, the discrete Fourier series expansion is given by
$$f = \sum_{j=1}^n \tilde f_j \psi_j,$$
where $\tilde f_j =  f^\mathsf{T}\psi_j = \psi_j^\mathsf{T}f$ are Fourier coefficients.

 \section{Fiedler vectors}
\index{Fiedler vector}

The connection between the eigenfunctions of continuous and discrete Laplacians have been well established by many authors \citep{gladwell.2002,tlusty.2007}. Many properties of eigenfunctions of  Laplace-Beltrami operator have discrete analogues. The second eigenfunction of the  graph Laplacian is called the Fiedler vector and it has been studied in connection to the graph and mesh manipulation, manifold learning and the minimum linear arrangement problem \citep{fiedler.1973,ham.2005,levy.2006,ham.2004,ham.2005}.

Let $G = \{V,E\}$ be the graph with the vertex set $V$ and the edge set $E$. We will simply index the node set as $V = \{1,2 ,\cdots, n\}$. If two nodes $i$ and $j$ form an edge, we denote it as $i \sim j$.  The edge weight between $i$ and $j$ is denoted as $w_{ij}$. For a measurement vector ${\bf f} = (f_1, \cdots, f_n)^{\top}$ observed at the $n$ nodes,  the discrete Dirichlet energy  is given by
\begin{eqnarray} \mathcal{E} ({\bf f}) = {\bf f}^{\top} L {\bf f} =  \sum_{i,j=1}^n w_{ij} (f_i - f_j)^2 = \sum_{i \sim j} w_{ij}(f_i - f_j)^2.\label{eq:DEdiscrete}\end{eqnarray}
The discrete Dirichlet energy (\ref{eq:DEdiscrete}) is also called the linear placement cost in the minimum linear arrangement problem \citep{koren.2002}. Fielder vector ${\bf f}$ evaluated at $n$ nodes is obtained as the minimizer of the quadratic polynomial:
$$ \min_{\boldsymbol f}   \mathcal{E} (f)$$
subject to the quadratic constraint
\begin{eqnarray} \| {\bf f} \|^2 = {\bf f}^{\top}{\bf f} = \sum_i f_i^2 = 1. \label{eq:fiedlerconstraint} \end{eqnarray}
The solution can be interpreted as the kernel principal components of a Gram matrix given by the generalized inverse of $L$ \citep{ham.2004,ham.2005}.
Since the eigenvector $\psi_1$ of Laplacian is  orthonormal with eigenvector $\psi_0$, which is constant,
we also have an additional constraint:
\begin{eqnarray} \sum_{i} f_i =0.   \label{eq:fiedlerconstraint2} \end{eqnarray}
This optimization problem was first introduced for the minimum linear arrangement problem in 1970's \citep{hall.1970,koren.2002}. The optimization can be solved using the Lagrange multiplier as follows \citep{holzrichter.1999}.
\index{graph!Laplacian}
\index{eigenfunctions!graph Laplacian}
\index{kernel!principal components}
\index{matrix!Gram}

Let $g$ be the constraint (\ref{eq:fiedlerconstraint}) so that
$$g({\bf f})  = {\bf f}^{\top}{\bf f} - 1 = 0.$$ Then the constrainted minimum should satisfy
\begin{eqnarray} \nabla \mathcal{E} - \mu \nabla g  =0, \label{eq:fiedler1}\end{eqnarray}
where $\mu$ is the Lagrange multiplier. (\ref{eq:fiedler1}) can be written as
\begin{eqnarray} 2L{\bf f} - \mu {\bf f} =0 \label{eq:fiedler2}\end{eqnarray}
Hence, ${\bf f}$ must be the eigenvector of $L$ and $\mu/2$ is the corresponding eigenvalue. By multiplying ${\bf f}^{\top}$ on the both sides of (\ref{eq:fiedler2}), we have
$$2{\bf f}^{\top}L{\bf f} = \mu {\bf f}^{\top} {\bf f} = \mu.$$
Since we are minimizing ${\bf f}^{\top} L {\bf f}$,
$\mu/2$ should be the second eigenvalue $\lambda_1$.

In most literature \citep{holzrichter.1999}, the condition $\sum_{i} f_i = 0$ is incorrectly stated as a necessary constraint for the Fiedler vector. However, the constraint $\sum_i f_i = 0$ is not really needed in minimizing the Dirichlet energy. This can be further seen from introducing a new constraint
$$ h({\bf f}) = {\bf e}^{\top}{\bf f} = \sum_i f_i = 0,$$
where ${\bf e} = (1, \cdots, 1)^{\top}$.

\begin{figure}[t]
\centering
\includegraphics[width=1\linewidth]{diffusion-graphlaplacian.pdf}
\caption{A weighted graph with weights $W$ and the graph Laplacian $L$. The weights are simply the adjacency matrix. The second eigenvector $\psi_1$ is given as numbers beside nodes. Left: This example is given in \citet{hall.1970}. The maximum geodesic distance is obtained between the nodes 1 and 3, which are also hot and cold spots. Right: There are two hot spots 1 and 5 which corresponds to two maximal geodesic paths 1-4-2-3 and 5-4-2-3 \citep{chung.2011.MLMI}.}
\label{fig:graphlaplacian}
\end{figure}

The constraint (\ref{eq:fiedlerconstraint}) and (\ref{eq:fiedlerconstraint2}) forces $\psi_1$ to have at least two differing {\em sign domains} in which $\psi_1$ has one sign. But it is unclear how many differing sign domains $\psi_1$ can possibly have. The upper bound is given by Courant's nodal line theorem \citep{courant.1953,gladwell.2002,tlusty.2007}. The {\em nodal set} of eigenvector $\psi_i$ is defined as the zero level set $\psi_i(p) = 0$. Courant's nodal line theorem states that the nodal set of the $i$-th eigenvector $\psi_{i}$ divides the graph into no more than $i$ sign domains. Hence, the second eigenvector has exactly 2 disjoint sign domains. At the positive sign domain, we have the global maximum and at the negative sign domain, we have the global minimum. This property is illustrated in Figure \ref{fig:graphlaplacian}.
\index{Courant's nodal line theorem} However, it is unclear where the global maximum and minimum are located. The concept of tightness is useful in determining the location.

\begin{definition}
For a function ${\bf f}$ defined on vertex set $V$ of $G$, let $G_s^-$ be the subgraph of $G$ induced by the vertex set $V_s^- = \{ i \in V  | f_i  < s \}$. Let $G_s^+$ be the subgraph of $G$ induced by the vertex set $V_s^+ = \{ i \in V | f_i  > s \}$. For any $s$, if $G_s^-$ and $G_s^+$ are either connected or empty, then ${\bf f}$ is tight  \citep{tlusty.2007}.
\end{definition}

\begin{figure}[t]
\centering
\includegraphics[width=0.8\linewidth]{diffusion-cycletight.pdf}
\caption{A path with with positive ($G_0^+$) and negative ($G_0^-$) sign domains. Due to symmetry, the possible eigenfunction $\psi_1$ has to be an odd function.}
\label{fig:cycletight}
\end{figure}

When $s=0$, $G_0^+$ and $G_0^-$ are sign graphs. If we relax the condition so that $G_s^+$ contains nodes satisfying $f_i \geq s$, we have weak sign graphs. It can be shown that the second eigenvector on a graph with maximal degree 2 (cycle or path) is tight \citep{tlusty.2007}. Figure \ref{fig:cycletight} shows an example of a path with 11 nodes. Among three candidates for the second eigenfunction, (a) and (b) are not tight while (c) is. Note that the candidate function (a) have two disjoint components for $G_{0.5}^+$ so it can not be tight. In order to be tight,  the second eigenfunction cannot have a positive minimum or a negative maximum at the interior vertex in the graph \citep{gladwell.2002}. This implies that the second eigenfunction must decrease monotonically from the positive to negative sign domains as shown in (c). Therefore, the hot and cold spots must occur at the two end points $1$ and $11$, which gives the maximum geodesic distance of 11.
\index{graph!degree}

For a cycle, the argument is similar except that a possible eigenfunction has to be periodic and tight, which forces the hot and cold spots to be located at the maximum distance apart. Due to the periodicity, we will have multiplicity of eigenvalues in the cycle.
Although it is difficult to predict the location of maximum and minimums in general, the behavior of the second eigenfunction is predictable for an elongated graph; it provides an intrinsic geometric way of establishing natural coordinates.

\section{Heat kernel smoothing on graphs}
\index{heat kernel}
\index{graph!heat kernel}

{\em Heat kernel smoothing} was originally introduced in the context of filtering out cortical surface data defined on mesh vertices obtained from 3D medical images  \citep{chung.2005.IPMI,chung.2005.NI}. The formulation uses the tangent space projection in approximating the heat kernel by iteratively applying Gaussian kernel with smaller bandwidth. Recently proposed spectral formulation to heat kernel smoothing \citep{chung.2015.MIA} constructs the heat kernel analytically using the eigenfunctions of the Laplace-Beltrami (LB) operator, avoiding the need for the linear approximation used in \citep{chung.2005.IPMI,han.2006}. Since surface meshes are graphs, heat kernel smoothing can be used to smooth noisy data defined on network nodes.

Instead of Laplace-Beltrami operator for cortical surface, graph  Laplacian is used to construct the discrete version of heat kernel smoothing. The connection between the eigenfunctions of continuous and discrete Laplacians has been well established by several studies \citep{gladwell.2002,tlusty.2007}. Although many have introduced the discrete version of heat kernel in computer vision and machine learning, they mainly used the heat kernels to compute shape descriptors  or to define a multi-scale metric \citep{belkin.2006,sun.2009,bronstein.2010, deGoes.2008}. These studies did not use the heat kernel in filtering out  data on graphs. There have been significant developments in kernel methods in the machine learning community \citep{bernhard.2002,nilsson.2007,shawe.2004,steinke.2008,yger.2011}. However, the heat kernel has never been used in such frameworks. Most kernel methods in machine learning deal with the linear combination of kernels as a solution to penalized regressions. On the other hand, our kernel method does not have a penalized cost function.

\subsection{Heat kernel on graphs}
The {\em discrete heat kernel} $K_{\sigma}$ is a positive definite symmetric matrix of size $p \times p$ given by
\begin{eqnarray} K_{\sigma} = \sum_{j=1}^p e^{-\lambda_j \sigma} \psi_j\psi_j^\mathsf{T}, \label{eq:dhk} \end{eqnarray}
where $\sigma$ is called the bandwidth of the kernel. Figure \ref{fig:Lshape-basis} displays heat kernel with different bandwidths at a L-shaped domain. Alternately, we can write (\ref{eq:dhk}) as
$$K_{\sigma} = \Psi e^{-{\sigma}\Lambda } \Psi^\mathsf{T},$$
where  $e^{-{\sigma}\Lambda }$ is the matrix logarithm of $\Lambda$. To see positive definiteness of the kernel,  for any nonzero $x \in \mathbb{R}^p$,
\begin{eqnarray*}
x^\mathsf{T} K_{\sigma} x &=& \sum_{j=1}^p e^{-\lambda_j \sigma} x^\mathsf{T}\psi_j\psi_j^\mathsf{T}x  \\
                &=& \sum_{j=1}^p e^{-\lambda_j \sigma} ( \psi_j^\mathsf{T}x )^2 > 0.\end{eqnarray*}
When $\sigma=0$, $K_{0} = I_p$, identity matrix. When $\sigma=\infty$, by interchanging the sum and the limit, we obtain
$$K_{\infty} =  \psi_1\psi_1^\mathsf{T} = {\bf 1} {\bf 1}^\mathsf{T}/p.$$
$K_{\infty}$ is a degenerate case and the kernel is no longer positive definite. Other than these specific cases, the heat kernel is not analytically known in arbitrary graphs.

Heat kernel is doubly-stochastic \citep{chung.1997} so that
$$K_{\sigma} {\bf 1} = {\bf 1}, \; {\bf 1}^\mathsf{T} K_{\sigma} = {\bf 1}^\mathsf{T}.$$
Thus, $K_{\sigma}$ is a probability distribution along columns or rows.

Just like the continuous counterpart,  the discrete heat kernel is also multiscale and has the scale-space property. Note
\begin{eqnarray*} K_{\sigma}^2 &=& \sum_{i,j=1}^p e^{-(\lambda_i + \lambda_j) \sigma} \psi_i\psi_i^\mathsf{T} \psi_j\psi_j^\mathsf{T}\\
&=& \sum_{j=1}^p e^{-2\lambda_j \sigma} \psi_j\psi_j^\mathsf{T} = K_{2\sigma}.
\end{eqnarray*}
We used the orthonormality of eigenvectors. Subsequently, we have
$$K_{\sigma}^n = K_{n\sigma}.$$

\subsection{Heat kernel smoothing on graphs}
\index{heat kernel smoothing}
\index{graph!smoothing}

Discrete heat kernel smoothing of measurement vector $f$  is then defined as convolution
\begin{eqnarray} K_{\sigma} * f = K_{\sigma}f  =\sum_{j=0}^p e^{-\lambda_j \sigma} {\tilde f}_j \psi_j, \label{eq:DHK} \end{eqnarray}
This is the discrete analogue of heat kernel smoothing first defined in \citep{chung.2005.IPMI}. In discrete setting, the convolution $*$ is simply a matrix multiplication. Thus, $$K_{0} *f = f$$ and
$$K_{\infty} *f =  \bar f {\bf 1},$$
where $\bar f = \sum_{j=1}^p f_j/p$ is the mean of signal $f$ over every nodes. When the bandwidth is zero, we are not smoothing data. As the bandwidth increases, the smoothed signal converges to the sample mean over all nodes.

Define the $l$-norm of a vector $f=(f_1, \cdots, f_p)^\mathsf{T}$ as
$$\parallel f \parallel_{l} =
            \Big(  \sum_{j=1}^p  \big| f_j \big|^{l}  \Big)^{1/l}.
$$
The matrix $\infty$-norm is defined as
$$
\parallel f \parallel_{\infty} =
            \max_{1 \leq j \leq p}  \big| f_j \big|.
$$

\begin{theorem} Heat kernel smoothing is a contraction mapping with respect to the $l$-th norm, i.e.,
\begin{eqnarray*} \| K_{\sigma} *f \|_l^l \leq \|  f \|_l^l. \label{eq:contraction} \end{eqnarray*}
\end{theorem}
{\em Proof.} Let kernel matrix $K_{\sigma} = (k_{ij})$. Then we have inequality
$$\| K_{\sigma} *f \|_l^l  = \sum_{i=1}^p  \sum_{j=1}^p |k_{ij}f_j |^l
\leq \sum_{j=1}^p |f_j|^l.
$$
We used Jensen's inequality and doubly-stochastic property of heat kernel. Similarly, we can show that heat kernel smoothing is a contraction mapping with respect to the $\infty$-norm as well.

Theorem 1 shows that heat kernel smoothing contracts the overall size of data. This fact can be used to skeltonize the blood vessel trees.

\subsection{Statistical properties}
Often observed noisy data $f$ on graphs is smoothed with heat kernel
$K_{\sigma}$ to increase the signal-to-noise ratio (SNR) and increases the statistical sensitivity
\citep{chung.2015.MIA}. We are interested in knowing how heat kernel smoothing will  affect on the statistical properties of smoothed data.

Consider the following addictive noise model:
\begin{eqnarray} f =    \mu + e, \label{eq:field} \end{eqnarray}
where $\mu$ is unknown signal and $\epsilon$ is  zero mean noise.  Let $e= (e_1, \cdots, e_p)^\mathsf{T}$. Denote $\mathbb{E}$ as expectation and $\mathbb{V}$ as covariance. It is natural to assume that the noise variabilities  at different nodes are identical, i.e.,
\begin{eqnarray} \mathbb{E} e_1^2 = \mathbb{E} e_2^2 = \cdots = \mathbb{E} e_p^2. \label{eq:eeq} \end{eqnarray}
Further, we assume that data at two nodes $i$ and $j$ to have less correlation when the distance between the nodes is large.
So covariance matrix  $$R_{e}  =  \mathbb{V} e = \mathbb{E} (e e^\mathsf{T}) = (r_{ij})$$ can be given by
\begin{eqnarray} r_{ij} = \rho( d_{ij}) \label{eq:rij} \end{eqnarray}
for some decreasing function $\rho$ and geodesic distance $d_{ij}$ between nodes $i$ and $j$.
 Note
$r_{jj} = \rho(0)$ with the understanding that $d_{jj}=0$ for all $j$. The off-diagonal entries of $R_e$ are smaller than the diagonals.

Noise $e$ can be further modeled as Gaussian white noise, i.e., Brownian motion or  the generalized derivatives of Wiener
process, whose covariance matrix elements are Dirac-delta. For the discrete counterpart, $r_{ij} = \delta_{ij}$, where $\delta_{ij}$ is Kroneker-delta with
$\delta_{ij}=1$ if $i=j$ and 0 otherwise.  Thus,
$$R_e = \mathbb{E} (e e^\mathsf{T}) = I_p,$$
the identity matrix of size $p \times p$. Since $\delta_{jj} \geq \delta_{ij}$, Gaussian white noise is a special case of (\ref{eq:rij}).

Once heat kernel smoothing is applied to (\ref{eq:field}), we have
\begin{eqnarray} K_{\sigma}*f = K_{\sigma}*\mu + K_{\sigma}*e. \label{eq:Kfield}\end{eqnarray}
We are interested in knowing how the statistical properties of model change from (\ref{eq:field}) to (\ref{eq:Kfield}).
For $R_e = I_p$, the covariance matrix of smoothed noise is simply given as
$$R_{K_{\sigma}*e}  = K_{\sigma} \mathbb{E} (e e^\mathsf{T}) K_{\sigma} =  K_{\sigma}^2 =K_{2\sigma}.$$
We used the scale-space property of heat kernel. In general, the covariance matrix  of smoothed data $K_{\sigma}* e$ is
given by
\begin{eqnarray*} R_{K_{\sigma}* e} = K_{\sigma} \mathbb{E} (e e^\mathsf{T}) K_{\sigma}  = K_{\sigma} R_e K_{\sigma}.\end{eqnarray*}

The variance of data will be often reduced after heat kernel smoothing in the following sense \citep{chung.2005.IPMI,chung.2005.NI}: \\

\begin{figure}[t!]
\centering
\includegraphics[width=1\linewidth]{kernel-graphsr.pdf}
\caption{From top left to right: 3D lung vessel tree. Gaussian noise is added to one of the coordinates. 3D graph constructed using 6-connected neighbors.  The numbers are the kernel bandwidth $\sigma$.}
\label{fig:lung-tree}
\end{figure}

\begin{theorem}
\label{thm:diffusionvar}
Heat kernel smoothing reduces variability, i.e.,
$$\mathbb{V} (K_{\sigma}* f)_j \leq \mathbb{V} f_j \label{eq:varreduction}$$
for all $j$. The subscript $_j$ indicates the $j$-th element of the vector.
\end{theorem}
{\em Proof.} Note
$$\mathbb{V} (K_{\sigma}* f)_j = \mathbb{V} (K_{\sigma}* e)_j = \mathbb{E} \Big( \sum_{i=1}^p k_{ij} e_i \Big)^2.$$
Since $(k_{ij})$ is doubly-stochastic, after applying Jensen's inequality, we obtain
$$ \mathbb{E} \Big( \sum_{i=1}^p k_{ij} e_i \Big)^2 \leq \mathbb{E} \Big(  \sum_{i=1}^p k_{ij} e_i^2 \Big) = \mathbb{E} e_i^2.$$
For the last equality, we used the equality of noise variability (\ref{eq:eeq}). Since $\mathbb{E} f_j = \mathbb{E} e_i^2$, we proved the statement. $\square$

Theorem \ref{thm:diffusionvar} shows that the variability of data decreases after heat kernel smoothing.

\subsection{Skeleton representation using heat kernel smoothing}

\begin{figure}[t]
\centering
\includegraphics[width=0.8\linewidth]{diffusion-lungr.pdf}
\caption{The skeleton representation of vessel trees. Using the heat kernel series expansion with bandwidth $\sigma=1$ and 6000 basis, we upsampled the binary segmentation at 2, 4, 6 times (clockwise from top right) larger than the original size (top left).}
\label{fig:lung-skel}
\end{figure}

Discrete heat kernel smoothing can be used to smooth out and present very complex patterns and get the skeleton representation. Here, we show how it is applied to the 3D graph obtained from the computed tomography (CT) of human lung vessel trees \citep{chung.2018.EMBCb,castillo.2009, wu.2013}. In this example, the 3D binary vessel segmentation from CT was obtained using the multiscale Hessian filters at each voxel \citep{frangi.1998,korfiatis.2011,shang.2011}. The binary segmentation was converted into a 3D graph by taking each voxel as a node and connecting neighboring voxels.  Using the 18-connected neighbor scheme, we connect two voxels only if they touch each other on their faces or edges.  If voxels are only touching at their corner vertices, they are not considered as connected. If the 6-connected neighbor scheme is used, we will obtain far sparse adjacency matrix and corresponding graph Laplacian. The eigenvector of graph Laplacian is obtained using  an Implicitly Restarted Arnoldi Iteration method \citep{lehoucq.1996}. We used 6000 eigenvectors. Note we cannot have more eigenvectors than the number of nodes.

As an illustration, we performed heat kernel smoothing on simulated data. Gaussian noise is added to one of the coordinates (Figure \ref{fig:lung-tree}). Heat kernel smoothing is performed on the noise added coordinate. Numbers in  Figure \ref{fig:lung-tree} are kernel bandwidths. At $\sigma=0$, heat kernel smoothing is equivalent to Fourier series expansion. Thus, we get the almost identical result. As the bandwidth increases, smoothing converges to the mean value.  Each disconnected regions should converge to their own different mean values.  Thus, when $\sigma=10000$,  the regions that are different colors are regions that are disconnected. This phenomena is related to the hot spots conjecture in differential geometry \citep{banuelos.1999, chung.2011.MLMI}.The number of disconnected structures can be obtained counting the zero eigenvalues.

The technique can be used to extract the skeleton representation of vessel trees. We perform heat kernel smoothing on node coordinates with $\sigma=1$. Then rounded off the smoothed coordinates to the nearest integers. The rounded off coordinates were used to reconstruct the binary segmentation. This gives the thick trees in Figure \ref{fig:lung-skel} (top left). To obtain thinner trees, the smoothed coordinates were scaled by the factor of 2, 4 and 6 times before rounding off. This had the effect of increasing the image size relative to the kernel bandwidth thus obtaining the skeleton representation of the complex blood vessel (Figure \ref{fig:lung-skel} clockwise from top right) \citep{lindvere.2013,cheng.2014}. By connecting the voxels sequentially, we can obtain the graph representation of the skeleton as well. The method can be easily adopted for obtaining the skeleton representation of complex brain network patterns.

\subsection{Diffusion wavelets}

Consider a traditional wavelet basis $W_{t,q}(p)$ obtained from a mother wavelet $W$ with scale and translation parameters $t$ and $q$ in Euclidean space \citep{kim.2012.NIPS}:
\begin{eqnarray} W_{t, q}(p) = \frac{1}{t}W \big(\frac{p-q}{t} \big). \label{eq:Wtq} \end{eqnarray}
The wavelet transform of a signal $f(p)$ is given by kernel
\begin{eqnarray*}
     \langle W_{t,q}, f \rangle = \int_{\mathcal{M}} W_{t,q}(p)f(p) \;d\mu(p).
\end{eqnarray*}

Scaling a function on an arbitrary manifold including graph is trivial. But the difficulty arises when one tries to translate a mother wavelet. It is not straightforward to generalize the Euclidean formulation (\ref{eq:Wtq}) to an arbitrary manifold,
due to the lack of regular grids  \citep{nain.2007,bernal.2008}. The recent work based on the diffusion wavelet bypasses this problem also by taking bivariate kernel as a mother wavelet \citep{antoine.2010,hammond.2011,mahadevan.2006, kim.2012.NIPS}.  By simply changing the second argument of the kernel, it has the effect of translating the kernel. The diffusion wavelet construction has been fairly involving so far.  However, it can be shown to be a special case of the heat kernel regression with proper normalization. Following the notations in \citet{antoine.2010,hammond.2011,kim.2012.NIPS},
 diffusion wavelet $W_{t,q}(p)$ at position $p$ and scale $t$ is given by
$$W_{t,q}(p) = \sum_{j=0}^k g(\lambda_j t)\psi_j(p)\psi_j(q),$$
for some scale function $g$. If we let $\tau_j = g(\lambda_j t)$, the diffusion wavelet transform
is given by
\begin{eqnarray} \langle W_{t,q}, f \rangle &=& \int_{\mathcal{M}} W_{t,q}(p)f(p) \;d\mu(p) \nonumber \\
& = &  \sum_{j=0}^k  g(\lambda_j t) \psi_j(q)   \int_{\mathcal{M}}  f(p) \psi_j(p) \; d\mu(p)  \nonumber \\
 &=& \sum_{j=0}^k \tau_j f_j \psi_j(q),   \label{eq:diffusion-waveletregression}
 \end{eqnarray}
 where $f_j = \langle f, \psi_j \rangle$ is the Fourier coefficient. Note (\ref{eq:diffusion-waveletregression}) is the kernel regression \citep{chung.2015.MIA}. Hence, the diffusion wavelet transform can be simply obtained by doing the kernel regression without an additional wavelet machinery as done in \citet{kim.2012.NIPS}.
Further, if we let $g(\lambda_j t) = e^{-\lambda_j t}$, we have
$$W_{t,p}(q) = \sum_{j=0}^k e^{-\lambda_j t} \psi_j(p)\psi_j(q),$$
which is a heat kernel. The bandwidth $t$ of heat kernel controls resolution while the translation is done by shifting one argument in the kernel.

\section{Laplace equation}
\index{cortical thickness!Laplace equation}
\index{Laplace equation}
\index{Glerkin's method}
\index{Iterative residual fitting}

In this section, we will show hot to solve for steady state of diffusion on a graph. The distribution of fictional charges within the two boundaries sets up a scalar potential field $\Psi$, which satisfies the Poisson equation
$$\Delta \Psi = \frac{\partial^2 \Psi}{\partial x^2} + \frac{\partial^2 \Psi}{\partial y^2} +\frac{\partial^2 \Psi}{\partial z^2} = \frac{\rho}{\epsilon_0},$$
where $\rho$ is the total charge within the boundaries. If we set up the two boundaries at different potential, say at $\Psi_{0}$ and $\Psi_1$, without enclosing any charge, we have the Laplace equation
$$ \Delta \Psi = 0.$$
By solving the Laplace equation with the two boundary condition, we obtain the potential field $\Psi$. Then the electric field perpendicular to the isopotential surfaces is given by
$ - \nabla \Psi$. The Laplace equation is mainly solved using the finite difference scheme. The electric field lines radiate from one conducting surface to the other without crossing each other. By tracing the electric field line on the graph, we obtain the geometric pattern of the graph.

The underlying framework is identical to the Laplace equation based surface flattening or cortical thickness estimation \citep{jones.2000,chung.2010.NI}. Without using the finite difference scheme, we can use an analytic approach for solving the Laplace equation in an arbitrary graph. The proposed method is essentially Galerkin's  method \citep{kirby.2000}. Galerkin's method usually discretize partial differential equations and integral equations as a collection of linear equations involving  basis functions. The linear equations are then usually solved in the least squares fashion. The iterative residual fitting (IRF) algorithm \citep{chung.2008.sinica} can be considered as a special case of Glerkin's method.

The solution of the Laplace equation is approximated as a finite expansion
$$ f(p) = \sum_{j=0}^{k} c_j \psi_j(p).$$
Consider following boundary conditions
\begin{eqnarray} f(p) = 1, \; p \in G_+, \mbox{ and } f(p) = -1, \; p \in G_-,
\end{eqnarray}
where $G_+$ and $G_-$ are subgraph of $G$. We may take $G_+$ and $G_-$ at the two extreme nodes in the minimum spanning tree. The boundary conditions satisfy
\begin{eqnarray} 1 = \sum_{j=0}^k c_j \psi_j(p_{2i}), \;p_{2i} \in  G_+ \label{eq:galerkin1}\end{eqnarray}
and
\begin{eqnarray} -1 = \sum_{j=0}^k c_j \psi_j(p_{3i}), \;p_{3i} \in G_- \label{eq:galerkin2}.\end{eqnarray}
In the interior region $G \backslash ( G_+ \cup G_-)$, by taking the Laplacian on the expansion $f(p) = \sum_{j=0}^k c_j \psi_j (p)$, we have
\begin{eqnarray} 0 = \sum_{j=0}^k c_j \lambda_j \psi_j(p_{1i}), \;p_{1i} \in G \backslash ( G_+ \cup G_-).\label{eq:galerkin3} \end{eqnarray}
We may assume that the number of nodes in $G_+$ and  $G_-$ are substantially smaller than the number of nodes in $G \backslash ( G_+ \cup G_-)$. So possibly we need to subsample the the interior region. We assume that there are $a, b$ and $c$ number of sampling nodes for equations  (\ref{eq:galerkin1}), (\ref{eq:galerkin2}) and (\ref{eq:galerkin3}) respectively. We now combine linear equations (\ref{eq:galerkin1}), (\ref{eq:galerkin2}) and (\ref{eq:galerkin3}) together in a matrix form:
\begin{eqnarray} \underbrace{\left(\begin{array}{c}
0 \\
  \vdots \\
  0\\
 1\\
 \vdots\\
 1\\
 -1\\
 \vdots\\
 -1
\end{array}\right)}_{{\bf y}} =\underbrace{ \left (\begin{array}{ccc}
\lambda_1 \psi_1(p_{11})& \cdots & \lambda_k \psi_k(p_{11})\\
  \vdots & \ddots & \vdots \\
 \lambda_1 \psi_1(p_{1a})& \cdots & \lambda_k (p_{1a}) \\
   \psi_1(p_{21}) & \cdots & \psi_k(p_{21}) \\
    \vdots & \ddots & \vdots \\
   \psi_1(p_{2b}) & \cdots & \psi_k(p_{2b}) \\
   \psi_1(p_{31}) & \cdots & \psi_k(p_{31}) \\
        \vdots & \ddots & \vdots \\
    \psi_1(p_{3c}) & \cdots & \psi_k(p_{3c}) \\
\end{array}\right)}_{\bf \Psi} \underbrace{\left(\begin{array}{c}
c_1 \\
c_2\\
  \vdots \\
  c_{k-1}\\
c_k
\end{array}\right)}_{\bf C}. \end{eqnarray}
The above matrix equation can be solved by the least squares method:
$$\widehat{\bf C} = ({\bf \Psi} ' {\bf \Psi})^{-1}{\bf \Psi} {\bf y}.$$
In order for the matrix ${\bf \Psi} ' {\bf \Psi}$ to have the inverse, the total number of sampling voxels ($a+b+c$) should be larger than the total number of basis $k$, which is likely to be true for brain images so there is no need to use the pseudo-inverse here.

\section*{Acknowledgements}
The part of this study was supported by NIH grants NIH R01 EB022856 and R01 EB028753. We would like to thank Yuan Wang of University of South Carolina for the providing Gibbs phenomenon plot and Gurong Wu  of University of Norh Carolina for providing lung CT scans.

\bibliographystyle{agsm}

\chapter{Random Fields Theory}
\index{random field theory}
\index{fields ! random}

General linear models (GLM) are often constructed and used in statistical inference  at the voxel level  in brain imaging.
In this paper, we explore the basics of random fields and the multiple comparisons on the random fields, which are
 necessary to properly threshold statistical maps for the whole image at specific statistical significance level. The multiple comparisons are crucial in determining overall statistical significance in correlated test statistics over the whole brain. In practice, $t$- or $F$-statistics in adjacent voxels are correlated. So there is the problem of multiple comparisons, which we have simply neglected up to now. For multiple comparisons that account for spatially correlated test statistics, various methods were proposed: Bonferroni correction, random field theory \citep{ worsley.1994, worsley.1996}, false discovery rates \citep{benjamini.1995, benjamini.2001, genovese.2002} and permutation tests \citep{nichols.2002}. Among them, we will explore the random field approach.

\section{Introduction}

Suppose we measure temperature $Y$ at position $x$ and time $t$ in a classroom $M \in
\mathbb{R}^3$. Since every measurement will be error-prone, we
model the temperature as
$$Y(x,t) = \mu(x,t) + \epsilon(x,t)$$
where $\mu$ is the unknown signal and $\epsilon$ is the
measurement error. The measurement error can be modelled as a
random variable. So at each point $(x,t) \in M \otimes
\mathbb{R}^+$, measurement error $\epsilon(x,t)$ is a random
variable. The collection of random variables $$\{\epsilon(x,t):
(x,t) \in M \otimes \mathbb{R}^+\}$$ is called a {\em stochastic
process}. The generalization of a continuous stochastic process defined in $\mathbb{R}$ to a higher dimensional abstract space indexed by a spatial variable  is called a {\em random field}. For an introduction to random fields, see \citet{adler.2007}, \citet{dougherty.1999} and \citet{yaglom.1987}. A formal measure theoretic definition can be found in \citet{adler.1981} and \citet{gikhman.1996}.

In brain imaging studies, it is necessary to model measurements at each voxel as a random field. For instance, in the deformation-based morphometry (DBM), deformation fields are usually modeled as continuous random fields \citep{chung.2001.ni}. In the random field theory as used in \citep{worsley.1994, worsley.1996}, measurement $Y$ at voxel position $x \in \mathcal{M}$ is modeled  as
$$Y(x) = \mu(x) + \epsilon(x),$$
where $\mu$ is the unknown signal to be estimated and $\epsilon$ is the
measurement error. The measurement error at each fixed $x$ can be modeled as a
random variable. Then the collection of random variables $\{\epsilon(x): x \in \mathcal{M} \}$ is called a {\em stochastic
process} or {\em random field}. The more precise measure-theoretic definition can be found in \citep{adler.2007}. Random field modeling can be done beyond the usual Euclidean space to curved cortical and subcortical manifolds \citep{joshi.1998, chung.2003.ni}.

\section{Random Fields}
We start with defining a random field more formally using random variables.  Our construction follows from \citet{adler.1981}.

\begin{definition}
Given a probability space, a random field $T(x)$ defined in $\mathbb{R}^n$ is a function such that for every fixed $x \in \mathbb{R}^n$, $T(x)$ is a random variable on the probability space.
\end{definition}

\begin{definition}
The  covariance function $R(x,y)$ of a random field $T$ is defined as
$$R(x,y)= \mathbb{E}  \big[ T(x)- \mathbb{E} T(x) \big] \big[ T(y)- \mathbb{E} T(y) \big].$$
\end{definition}

Consider a random field $T$. If  the joint distribution $$F_{x_1,\cdots, x_m}(z_1,\cdots, z_m) = P\big[  T(x_1) \leq z_1, \cdots, T(x_m) \leq z_m  \big]$$
is invariant under the translation $$(x_1,\cdots,x_m) \to (x_1+\tau, \cdots, x_m +\tau),$$ $T$ is said to be stationary or homogeneous. For a stationary random field $T$, we can show
$$\mathbb{E} T(x) = \mathbb{E} T(0)$$
and subsequently
$$R(x,y)=f(x-y)$$ for some function $f$. Although the converse is not always true, such a case is not often encountered in practical applications \citep{yaglom.1987}  so we may equate the stationarity with the condition $$\mathbb{E} T(x) = \mathbb{E} T(0), \; R(x,y)=f(x-y).$$
A special case of stationary fields is an isotropic field which requires the covariance function to be rotation invariant, i.e. $$R(x,y) = f(\| x - y\|)$$ for some function $f$. $\| \cdot \|$ is the geodesic distance in the underlying manifold.

\index{covariance fields}
\index{fields ! covariance}

\subsection{Gaussian Fields}

\index{fields ! Gaussian}
\index{Gaussian fields}

The most important class of random fields is Gaussian fields. A more rigorous treatment can be found in \citet{adler.2007}. Let us start defining a multivariate normal distribution from a Gaussian random variable.

\begin{definition}
A random vector $T=(T_1,\cdots, T_m)$ is multivariate normal if
$\sum_{i=1}^m c_i T_i$ is Gaussian for every possible $c_i \in \mathbb{R}$.
\end{definition}
Then a Gaussian random field can be defined from a multivariate normal distribution.
\begin{definition}
\label{def:gaussian}
A random field $T$ is a {\em Gaussian random field} if $T(x_1),\cdots, T(x_m)$ are
multivariate normal for every $(x_1,\cdots, x_m) \in \mathbb{R}^m$.
\end{definition}
An equivalent definition to Definition \ref{def:gaussian} is as follows.
\begin{definition}
$T$ is a  Gaussian random field if the finite joint distribution\\
$F_{x_1,\cdots, x_m}(z_1,\cdots, z_m)$ is a multivariate normal for every $(x_1,\cdots, x_m)$.
\end{definition}

$T$ is a mean zero Gaussian field if $\mathbb{E}T(x) = 0$ for all $x$. Because any mean zero multivariate normal distribution can be completely characterized by its covariance matrix, a mean zero Gaussian random field $T$ can be similarly  determined by its covariance function $R$. Two fields $T$ and $S$ are
independent if $T(x)$ and $S(y)$ are independent for every $x$
and $y$. For mean zero Gaussian fields $T$ and $S$, they are
independent if and only if the cross-covariance function
$$R(x,y)=\mathbb{E} \big[ T(x)T(y) \big]$$
vanishes for all $x$ and $y$.

Given two arbitrary mean zero
Gaussian fields, is there mapping that makes them independent? Let
$e=(e_1(t),e_2(s))^{\top}$ be a vector field. Let $A$ be a constant
matrix. Consider transformation $Ae$ and its covariance
$$\mathbb{E} [Ae (Ae) ^{\top}] = A\mathbb{E} [ee ^{\top}] A ^{\top}.$$
Note that
$\mathbb{E} [ee ^{\top}]$ is symmetric and its diagonal terms are
positive so it is a symmetric positive definite matrix so we have
a singular value decomposition of the form $\mathbb{E}[ee ^{\top}] =
QDiag(\lambda_1,\lambda_2)Q ^{\top}$ where $Q$ is an orthogonal matrix.
Simply let $A=Q ^{\top}$ and it should make the component of $Ae$
uncorrelated for all $t$ and $s$. But they are still not
independent.

The Gaussian white noise is a Gaussian random field with the Dirac-delta function $\delta$ as the covariance function. Note the Dirac delta function is defined as $\delta(x) = \infty, x =0$, $\delta(x) = 0 x \neq 0$ and $\int \delta(x) = 1$. Numerically we can simulate the Dirac delta function as the limit of the sequence of Gaussian kernel $K_{\sigma}$ when $\sigma \to \infty$. The Gaussian white noise is simulated as an independent and identical Gaussian random variable at each voxel.

\subsection{Derivative of Gaussian Fields}

\index{fields ! derivatives}

Any linear operation $f$ on Gaussian fields is again Gaussian fields.
Suppose $\mathcal{G}$ be a collection of Gaussian random fields. Then $f(\mathcal{G}) \subset \mathcal{G}$. For given $X, Y \in \mathcal{G}$, we have $c_1 X + c_2 Y \in \mathcal{G}$ again for all $c_1$ and $c_2$. Therefore, $\mathcal{G}$ forms an infinite-dimensional vector space. Not only the linear combination of Gaussian fields is again Gaussian but also the derivatives of Gaussian fields are Gaussian. To see this, we define the mean-square convergence.

\begin{definition}
A sequence of random fields $T_h$, indexed by $h$ converges to
$T$ as $h \to 0$ in mean-square if
$$\lim_{h \to 0} \mathbb{E} \big |T_h - T  \big|^2=0.$$
\end{definition}
We will denote the mean-square convergence using the usual limit notation:
$$\lim_{h \to 0} T_h = T.$$
The convergence in mean-square implies the convergence in mean. This can be seen from
$$\mathbb{E} \big|T_h  - T \big|^2 =  \mathbb{V} \big[T_h - T \big]^2 +\big( \mathbb{E} | T_h - T | \big)^2.$$
Now let $T_h \to T$ in mean square. Each term in the right hand side should also converges to zero proving the statement.

Now we define the derivative of field in mean square sense as
$$\frac{d T(x)}{d x} = \lim_{h \to 0} \frac{T(x+h)-T(x)}{h}.$$
Note that if $T(x)$ and $T(x+h)$ are Gaussian random fields, $T(x+h)-T(x)$ is again Gaussian, and hence the limit on the right hand side is again Gaussian. If $R$ is the covariance function of the mean zero Gaussian field $T$, the covariance function of its derivative field is given by
$$\mathbb{E} \Big[\frac{d T(x)}{d x}
\frac{d T(y)}{d y} \Big]=\frac{\partial ^2 R(x,y)}{\partial x
\partial y}.$$

Given zero mean Gaussian field $X(t), t =(t_1,\cdots,t_n) \in \mathbb{R}^n$, the Hessian  field $H(t)$ of $X(t)$ is given by
$$H(t) = \Big(\frac{\partial^2
X(t)}{\partial t_i \partial t_j}\Big).$$
If we have mean zero Gaussian random variables $Z_1,\cdots, Z_n, \mathbb{E} (Z_1 \cdots
Z_n) = 0$ if $n$ odd. Hence the expectation of the determinant of
Hessian of a mean zero Gaussian field vanishes. For $n$ even and
assuming isotropic covariance $R(t,s) = R(\|t-s\|)$, i.e.,
stationarity, we can further simplify the expression.

\subsection{Integration of Gaussian Fields}

\index{fields ! integration}

The integration of Gaussian fields is also Gaussian. To see this, define the integration of a random field as the limit of
Riemann sum. Let $\cup_{i=1}^n \mathcal{M}_i$ be a partition of $\mathcal{M}$, i.e.
$$\mathcal{M} = \cup_{i=1}^n \mathcal{M}_i \mbox{ and }
\mathcal{M}_i \cap \mathcal{M}_j = \emptyset \mbox{ if } i \neq j.$$
Let $x_i \in
\mathcal{M}_i$ and $\mu(\mathcal{M}_i)$ be the volume of $\mathcal{M}_i$. Then we define the integration of field $T$ as
$$\int_{\mathcal{M}} T(x) \; dx = \lim_{} \sum_{i=1}^n T(x_i)\mu(\mathcal{M}_i),$$
where the limit is taken as $\mu(\mathcal{M}_j) \to 0$ for all $j$.

Multiple integration is defined similarly. When we integrate a Gaussian field, it is the limit of a linear combination of
Gaussian random variables so it is again a Gaussian random variable. In general, any linear operation on Gaussian fields will result in  a Gaussian field.

Let $X(t)$ be a zero mean Gaussian fields in
$\Omega$ with covariance function $R$. Let's find the distribution of
$\int_{\Omega} X(t) \; dt$.
Obviously this is a zero mean Gaussian random variable so we only need to
find the second moment
\begin{eqnarray*} &&\mathbb{E} \big[\int_{\Omega} X(t)
\;dt \int_{\Omega} X(s) \;ds\big]\\
&=& \int_{\Omega}\int_{\Omega} \mathbb{E} [X(t)X(s)] \;dt \;ds\\
&=& \int_{\Omega}\int_{\Omega} R(t,s) \;dt \;ds.
\end{eqnarray*}

\subsection{$t$, $F$ and $\chi^2$ Fields}

\index{fields ! $t$-fields}
\index{fields ! $F$-fields}
\index{fields ! $\chi^2$-fields}

We can use i.i.d. Gaussian fields to construct  $\chi^2$-, $t$-, $F$-fields, all of which are extensively studied in \citep{cao.1999.stat, worsley.2004, worsley.1996, worsley.1994}. The $\chi^2$-field with $m$ degrees of freedom is defined as
$$T(x) = \sum_{i=1}^m X_i^2(x),$$
where $X_1,\cdots,X_m$ are independent, identically distributed Gaussian fields with zero mean and unit variance. Similarly, we can define $t$ and $F$ fields as well as Hotelling's $T^2$ field. The Hotelling's $T^2$-statistic has been widely used in detecting morphological changes in deformation-based morphometry \citep{cao.1999.stat, collins.1998, gaser.1999, joshi.1998, thompson.1997}. In particular,  \citep{cao.1999.stat} derived the excursion probability of the Hotelling's $T^2$-field and applied it to detect gender specific morphological differences.

\section{Convolution on Random Fields}
Consider the following integral
$$Y(t) = \int K(t,s)X(s) \; ds.$$
where $K$ is called the kernel of the integral.  Define {\em convolution} between kernel $K$ and random field $X$ as the above integral.
\begin{eqnarray*} Y(t) = K*X(t).\label{eq:lecture2-con}\end{eqnarray*}

Suppose  the kernel to be isotropic probability density, i.e. $K(t,s) =
K(t-s)$ and $\int K(t) \; dt =1.$ Further we may assume $K$ to be
unimodal with some parameter $\sigma$ such that
$$ \lim_{\sigma \to 0} K(t;\sigma) \to \delta(t),$$
the {Dirac-delta function}. Since the Dirac-delta function satisfies
$$\int \delta(t-s)f(s) \;ds = f(t),$$
it can be easily seen that
$$\lim_{\sigma \to 0} K(\cdot;\sigma)*X \to X.$$

\subsection{Kernel smoothing estimator}
Let $t=(t_1,\cdots,t_n)' \in
\mathbb{R}^n.$ The $n$-dimensional isotropic Gaussian kernel is
given by the products of $1$-dimensional Gaussian kernel:
$$K(t)=\prod_{i=1}^n \frac{1}{\sqrt{2\pi}}e^{-t_i^2/2}.$$
The isotropic kernel under linear transform $t \to Ht$ changes the
shape of the kernel to anisotropic kernel
$$K_H(t) = \frac{1}{det (H)} K(H^{-1}t).$$
Note the multivariate kernel $K_H$ is a probability distribution, i.e.,
$$\int  K_H(t) \; dt = 1.$$
$(\det H)^{-1}$ is the Jacobian of the transformation that normalize
the density. It is the distribution of $n$-dimensional
multivariate normal with the covariance matrix $HH'$, i.e.
$N(0,HH')$. $H$ is also called the {\em bandwidth matrix} in the
context of kernel smoothing and it measures the amount of
smoothing. It can be shown that $K_{H}$ satisfy the definition of
the Dirac-delta function as the eigenvalues $\lambda_i$ of $H$ go
to zero, i.e.
$$\lim_{\lambda_i \to 0} K_{H}(t) = \delta(t).$$
The limit of the sequence of the Gaussian kernels gives the
Dirac-delta function and this is how we implement the Dirac-delta
function in computer programs. From now on we let $H \to 0$ if all
$\lambda_i \to 0$ and $H \to \infty$ if all $\lambda_i \to
\infty$.

Suppose we have an additive model \begin{eqnarray*}  Y(t) = \mu(t) + \epsilon(t) \label{eq:model1}\end{eqnarray*} where
$e$ is a mean zero random field and $\mu$ is an unknown signal. In
image analysis, observations are so dense that we can take them to
be continues functional data. Then the kernel smoothing estimator
is given by
\begin{eqnarray} \widehat \mu(t) = K_{H}*Y(t)= \int K_{H}(t-s) Y(s)\;ds\label{eq:model2}\end{eqnarray}
As $H$ goes to zero, we are smoothing
less. To see this note that
$$\lim_{\sigma \to 0} \widehat \mu(t) = \int \delta(t-s) Y(s) \; ds = Y(t)$$
 From (\ref{eq:model2}),
$$\mathbb{E} \widehat \mu(t) = K_{H}*\mu(t) \to \mu(t) \mbox { as } \sigma \to 0$$
From the property of the Dirac-delta, as $H \to 0$, $K_{H}*\mu(t)$
converges to the true but unknown signal $\mu$. So
we can see that our kernel estimator becomes more unbiased as $H
\to 0$.

We can show that the estimator $ \widehat \mu(t)$ is a
solution to a heat equation and the condition $H \to \infty$ is
equivalent to the steady state that is reached when we diffuse heat for infinite
amount of time \citep{chung.2012.CNA}.

Other properties of kernel smoothing estimator is as follows.
Assuming $|\mu| \leq \infty$, \begin{eqnarray} \mathbb{E} \widehat \mu (t) \leq
\int K_H(t) \sup_{} \mu(t) \;dt \leq \sup_{} \mu(t).\end{eqnarray}

Similarly we can bound from below so that
\begin{eqnarray} \inf_{} \mu(t) \leq
\mathbb{E} \widehat \mu(t) \leq \sup_{} \mu(t) .
\label{eq:lecture3-inf}\end{eqnarray}

 Inequality (\ref{eq:lecture3-inf}) implies that smoothed signal will be smaller than the maximum and larger than
the minimum of the signal in average. Other interesting property is
\begin{eqnarray} \int K_H*Y(t) \;
dt &=& \int_t \int_s K_H(t-s)Y(s) \; ds\; dt\\
&=& \int Y(s) \; ds.\end{eqnarray}
Thus we have
$$\mathbb{E} \int \widehat \mu(t) \; dt = \int \mu(t) \;dt.$$
If $\mu(t)$ is a probability such as the transition probability in
Brownian motion, it implies that the total probability is
conserved even after smoothing.

Let $R_Y$ be the covariance function of field $Y$ with $\mathbb{E} Y =0$.
It is trivially $$R_Y(t,s) =
R_{\epsilon}(t,s) =\mathbb{E} [\epsilon(t)\epsilon(s)],$$
the covariance function of $\epsilon$. Then we can show that the covariance function of the
kernel smoother can be shown to be \begin{eqnarray} R(t,s) =\int \int
K_{H}(t-t')K_{H}(t-s')R_{\epsilon}(t',s') \;dt'
 \;ds'.\end{eqnarray}

\section{Numerical Simulation of Gaussian Fields}
For the random field theory based multiple correction to work, it is necessary to have smooth images. In this section, we show how to simulate smooth Gaussian fields by performing Gaussian kernel smoothing on white noise. This is the easiest way of simulating Gaussian fields.

White noise is defined as a random field whose covariance function is proportional to the Dirac-delta function $\delta$, i.e.
$$R(x,y) \propto \delta(x-y).$$
For instance, me may take $R(x,y) = \lim_{\sigma \to 0} K_{\sigma}(\|x
- y\|)$, the limit of the usual isotropic Gaussian kernel. White noise is usually characterized via generalized functions.

One example of white noise is the generalized derivative of
Brownian motion (Wiener process) called white Gaussian noise.

\begin{definition}
\label{def:brownian}
Brownian motion (Wiener process) $B(x), x \in \mathbb{R}^+$ is zero mean Gaussian
field with covariance function $$R_B(x,y) = \min(x,y).$$
\end{definition}

Following Definition \ref{def:brownian}, we can show ${\bf Var} B(x) = x$ by taking $x=y$ in the covariance function and $B(0)=0$ by letting $x=0$ in the variance. The increments of Wiener processes in nonoverlapping
intervals are independent identically distributed (iid) Gaussian. Further the paths of the Wiener process
is continous in the Kolmogorov sense while it is not differentiable. For a different but identical canonical
construction of Brownian motion, see \citep{oksendal.2010}.
Higher dimensional
Brownian motion can be generalized by taking each component of
vector fields to be i.i.d. Brownian motion.

\index{Brownian motion}
\index{Gaussian noise}

\begin{figure}[t]
\centering
\includegraphics[width=0.9\linewidth]{fields-IMA09.pdf}
\caption{Random fields simulation via iterated Gaussian kernel
smoothing with $\sigma=0.4$. $N(0,0.4^2)$. White noise, 1, 4 and 9
iterations in sequence.\label{fig:lec9-1}}
\end{figure}

Although the path of Wiener process is not differentiable, we can define the generalized derivative via integration by parts with a smooth function $f$
called a test function in the following way
$$f(x)B(x) = \int_0^x f(y)\frac{dB(y)}{dy} \;dy + \int_0^x \frac{f(y)}{dy}B(y)\;dy.$$
Taking the expectation on both sides we have
$$ \int_0^x f(y) \mathbb{E}\frac{dB(y)}{dy} \;dy =0.$$
It should be true for all smooth $f$ so $\mathbb{E}
\frac{dB(y)}{dy} =0$. Further it can be shown that the covariance
function of process $dB(y)/dy \propto \delta(x-y)$.

\index{Wiener process}

The Gaussian white noise can be used to construct smooth Gaussian
random fields of the form
$$X(x) = K * W(x) = K * \frac{dB(x)}{dx},$$
where $K$ is a Gaussian kernel. Since Brownian motion is zero mean Gaussian process, $X(x)$ is
obviously zero mean field with the covariance function
\begin{eqnarray}
R_X(x,y) &=& \mathbb{E} [K * W(x)K * W(y)]\\
&\propto&\int K(x-z)K(y-z) \; dz.\end{eqnarray} The case when $K$  is an
isotropic Gaussian kernel was investigated by D.O.
Siegmund and K.J. Worsley with respect to optimal filtering in
scale space theory \citep{siegmund.1996}.

In numerical implementation, we use the discrete white Gaussian noise which is simply a Gaussian random variable.

\begin{example}
Let $w$ be a discrete version of white Gaussian noise given by
$$w(x) = \sum_{i=1}^m Z_i \delta(x-x_i),$$
where i.i.d. $Z_i \sim N(0,\sigma_w^2)$. Note that
\begin{eqnarray} K* w(x) = \sum_{i=1}^m Z_iK(x-x_i).
\label{eq:fields-KW}\end{eqnarray}
The collection of random variables $K* w(y_1), \cdots, K*w(y_l)$ forms a
multivariate normal at arbitrary points $y_1,\cdots, y_l$. Hence
the field $K * w(x)$ is a Gaussian field.
\end{example}
The covariance function of the field \ref{eq:fields-KW} is given by
\begin{eqnarray} R(x,y) &=& \sum_{i,j=1}^m \mathbb{E}(Z_iZ_j) K(x-x_i)
K(y-x_j) \\
&=&\sum_{i=1}^m \sigma_w^2K(x-x_i) K(y-x_i).
 \end{eqnarray}
 As usual we may take $K$ to be a
Gaussian kernel. Let us simulate some Gaussian fields.

\begin{example}
The unknown signal is assumed to be $\mu(x,y) = \cos (10x) + \sin(8y), (x,y) \in [0,1]^2$ and
white noise error $w \sim N(0,0.4^2)$ which is shown in the top left of Figure \ref{fig:lec9-1}. Then iteratively more smooth version of Gaussian random fields are constructed by

\begin{verbatim}
w=normrnd(0,0.4,101,101);
smooth_w=w;
for i=1:10
  smooth_w=conv2(smooth_w,K,'same');
  figure;imagesc(smooth_w);colorbar;
end;
\end{verbatim}
with kernel weight {\tt K}.
\end{example}

\section{Statistical Inference on Fields}
\label{sec:MCC}
\index{fields ! statistical inference}

Given functional measurement $Y$, we have model
$$Y(x) =\mu(x) + \epsilon(x),$$
where $\mu$ is unknown signal and $\epsilon$ is a zero mean unit variance Gaussian field. We assume $x \in \mathcal{M} \subset \mathbb{R}^n$. In brain imaging, one of the most important problems is that of signal detection, which can be stated as the problem of identifying the regions of
statistical significance. So it can be formulated as an
inference problem $$H_0: \mu(x)=0 \mbox{ for all } x \in \mathcal{M} \mbox{ vs. }\;
H_1:\mu(x)
> 0 \mbox { for some } x \in \mathcal{M}.$$
Let
$$H_0(x):\mu(x) = 0$$
at a fixed point $x$. Then the null hypothesis $H_0$ is a collection of multiple hypotheses $H_0(x)$ over all $x$. Therefore, we have
$$H_0 = \bigcap_{x \in \mathcal{M}} H_0(x).$$
We may assume that $\mathcal{M}$ is the region of interest consisting of the finite number of voxels. We also have the corresponding point-wise alternate hypothesis $$H_1(x): \mu(x)
>0$$
and the alternate hypothesis $H_1$ is constructed as
$$H_1 = \bigcup_{x \in \mathcal{M}} H_0(x).$$
If we use $Z$-statistic as a test statistic, for instance, we will reject
each $H_0(x)$ if $Z > h$ for some threshold $h$.  So at each fixed $x$, for level $\alpha
= 0.05$ test, we need to have $h=1.64$.
However, if we threshold at $\alpha =0.05$, $5\%$ of observations are false positives.
Note that the false positives are pixels where we are incorrectly rejecting $H_0(x)$ when it is actually true.
However, these are the false positives related to testing $H_0(x)$. For determining the true false positives associated with testing $H_0$, we need to account for multiple comparisons.

\begin{definition}

\index{type-I error}
\index{error ! type-I}

The type-I error is the probability of  rejecting the null hypothesis (there is no signal) when the alternate hypothesis (there is a signal) is true.
\end{definition}
The type-I error is also called the {\em family-wise error rate} (FWER) and given by
\begin{eqnarray} \alpha &=& P(\mbox{
reject } H_0 \; | \; H_0 \mbox{ true }) \nonumber \\
&=& P(\mbox{ reject some } H_0(x) \;| \; H_0 \mbox{ true }) \nonumber\\
&=& P\Big(\bigcup_{x \in \mathcal{M}} \{Y(x) > h\} \; \Big| \; \mathbb{E} Y=0\Big). \label{eq:deform-alphacup}
\end{eqnarray}
Unfortunately, $Y(x)$ is correlated over $x$ and it makes the
computation of type-I error almost intractable for random fields
other than Gaussian.\\

\subsection{Bonferroni Correction}

\index{Bonferroni correction}
\index{multiple comparisons ! Bonferroni}

One standard method for dealing
with multiple comparisons is to use the Bonferroni correction. Note
that the probability measure is additive so that for any event $E_j$, we have \begin{eqnarray*}
P \Big(\bigcup_{j=1}^{\infty} E_j \Big) \leq \sum_{j=1}^{\infty} P(E_j).\end{eqnarray*} This
inequality is called Bonferroni inequality and it has been used in the construction of simultaneous
confidence intervals and multiple comparisons when the number of
hypotheses are small. From (\ref{eq:deform-alphacup}), we have
\begin{eqnarray} \alpha &=& P\Big(\bigcup_{x \in \mathcal{M}} \{Y(x) >
h\} \; \Big| \; \mathbb{E} Y=0\Big) \label{eq:deform-bonferoni1}\\
&\leq& \sum_{x \in \mathcal{M}} P\big(Y(x_j)>h \; | \; \mathbb{E} Y
=0\big)\label{eq:deform-bonferoni2}\end{eqnarray} So by controlling each type-I error
separately at
$$P\big(Y(x_j)>h \; | \; \mathbb{E} Y =0\big) < \frac{\alpha}{\# \mathcal{M}}$$
we can construct the correct level $\alpha$ test. Here $\# \mathcal{M}$ is the number of voxels.

The problem with the Bonferroni correction is that  it is too
conservative. The Bonferroni inequality  (\ref{eq:deform-bonferoni2}) becomes exact when the measurements across voxels are all independent, which is unrealistic. Since the measurements are expected to be  strongly correlated across voxels, we have highly correlated statistics. So in a sense, we have a less number of comparisons to make.

Let us illustrate the Bonferroni correction procedure using {\tt MATLAB}. Consider
$100 \times 100$ image $Y$ of standard normal random variables (Figure \ref{fig:bonferroni}). The threshold corresponding to the significance $\alpha = 0.05$ is 1.64.

\begin{figure}[t]
\includegraphics[width=1\linewidth]{bonferroni.pdf}
\centering
\caption{Image consisting of $N(0,1)$ noise. At the thresholding 1.64 corresponding to the significance level $\alpha = 0.05$, 5$\%$ of all pixels are false positives.}
\label{fig:bonferroni}
\end{figure}

\begin{verbatim}
Y=normrnd(0,1,100,100);
figure; imagesc(Y); colorbar; colormap('hot')

norminv(0.95,0,1)

ans =

    1.6449

[Yl, Yh] = threshold_image(Y, 1.64);
figure; imagesc(Yh); colormap('hot'); colorbar;
\end{verbatim}

By thresholding the image at 1.64, we obtain approximately about 5$\%$ of pixels as false positives. To account for the false positives, we perform the Bonferroni correction. For image of size $100 \times 100$, there are $10000$ pixels. Therefore, $\alpha/\# \mathcal{M} =0.05/ 10000= 0.000005 $ is the corresponding point-wise $p$-value and the corresponding threshold is 4.42. In this example,  there is no pixel that is higher than 4.42 so we are not detecting any false positives as expected.

\begin{verbatim}
n=100*100;
size(find(reshape(Y,n,1)>=1.64),1)/n
norminv(1-0.05/10000,0,1)

ans =

    4.4172
\end{verbatim}

\subsection{Rice Formula}
\index{Rice formula}
\index{multiple comparisons ! Rice formula}

We can obtain a less conservative estimate for (\ref{eq:deform-alphacup}) using the random field theory. Assuming $\mathbb{E} Y=0$, we have
\begin{eqnarray} \alpha(h) &=& P\Big(\bigcup_{x \in \mathcal{M}} \{Y(x) > h\}\Big) \nonumber \\
&=&1-  P\Big(\bigcap_{x \in \mathcal{M}} \{Y(x) \leq h  \}\Big)  \nonumber \\
&=& 1 - P \Big(\sup_{x \in \mathcal{M}} Y(x) \leq h \Big)  \nonumber \\
&=& P \Big(\sup_{x \in \mathcal{M}} Y(x) > h \Big). \label{eq:deform-supYx} \end{eqnarray}
In order to construct the $\alpha$-level test corresponding to $H_0$, we need to know the distribution of
the supremum of the field $Y$.
The corresponding $p$-value based on the supremum of the field, i.e. $\sup_{x \in \mathcal{M}} Y$, is called the {\em corrected $p$-value} to distinguish it from the usual $p$-value obtained from the statistic $Y$. Note that the p-value is the smallest $\alpha$-level at which the null hypothesis $H_0$ is rejected.

Analytically computing the exact distribution of the supremum of random fields is hard. If we denote $Z=\sup_{x \in \mathcal{M}} Y(x)$ and $F_Z$ to be the cumulative
distribution of $Z$, for the given $\alpha =0.05$, we can compuate
$h=1-F_Z^{-1}(\alpha)$. Then the region of statistically
significant signal is localized as $\{x \in \mathcal{M}: Y(x) > h\}$.

The distribution of supremum of Brownian motion is somewhat simple due to its independent increment properties. However, for smooth random fields, it is not so straightforward. Read \citep{adler.2000} for an overview of computing the distribution of the supremum of smooth fields.

Consider 1D smooth stationary Gaussian random process $Y(x), x \in \mathcal{M}=[0,1] \subset
\mathbb{R}$. Let $N_h$ to be the number of times $Y$ crosses over
$h$ from below (called upcrossing) in $[0,1]$. Then we have \begin{eqnarray*}
P\Big(\sup_{x \in
[0,1]} Y(x) > h\Big) &=& P(N_h \geq 1 \mbox{ or } Y(0) > h)\\
&\leq& P(N_h \geq 1) + P(Y(0) >h)\\
&\leq& \mathbb{E} N_h + P(Y(0) >h).\end{eqnarray*}
If $R$ is the covariance function of the field $Y$, we have
$$R(0) = \sigma^2 = \mathbb{E} Y^2(x).$$
It can be shown that from Rice formula \citep{adler.1993, rice.1944},
$$\mathbb{E} N_h = \frac{1}{\pi}\left(   \frac{-R''(0)}{R(0)} \right)^{1/2} \exp \left(\frac{h^2}{2\sigma^2}\right).$$
Also note that
$$P(Y(0) > h) =1-\Phi \Big(\frac{h}{\sigma} \Big)$$ where $\Phi$ is the
cumulative distribution function of the standard normal. Then from the inequality that bounds the cumulative distribution of the standard normal \citep{feller.1968}, we have \begin{eqnarray*}
\Big( 1-\frac{\sigma^2}{h^2} \Big)\frac{\sigma}{\sqrt{2\pi}
h}e^{-h^2/2\sigma^2} \leq 1-\Phi \Big(\frac{h}{\sigma} \Big) \leq
\frac{\sigma}{\sqrt{2\pi} h}e^{-h^2/2\sigma^2} \end{eqnarray*}
So \begin{eqnarray*} P\Big(\sup_{x \in [0,1]} Y(x) > h\Big) \leq \Big[c_1
+\frac{c_2}{\sqrt{2\pi} h}\Big] e^{-h^2/2\sigma^2}\end{eqnarray*}
for some $c_1$ and $c_2$.  In fact we can show
that
\begin{eqnarray*} P\Big(\sup_{x \in [0,1]} Y(x) > h\Big) = \Big[c_1
+\frac{c_2}{h} +O(h^{-2})\Big] e^{-h^2/2\sigma^2}.\end{eqnarray*}
\\

\subsection{Poisson Clumping Heuristic}

\index{multiple comparisons ! Poisson clumping heuristic}

To extend the Rice formula to a higher dimension, we need a different mathematical machinery.  For this method to work, the random field $Y$ needs to be sufficiently smooth and isotropic. The smoothness of a random field corresponds to the random field being differentiable. There are very few cases for which exact formulas for the excursion probability (\ref{eq:deform-supYx}) are known \citep{adler.1990}. For this reason, approximating the excursion probability is necessary for most cases.

From the {\it Poisson clumping heuristic} \citep{aldous.1989},
$$P\Big( \sup_{x \in \mathcal{M}} Y(x) <  h \Big) \approx \exp \biggl(-\frac{\| \mathcal{M} \|}{\mathbb{E} \|A_h\|} P\big( Y(x) \geq h\big)\biggl),$$
where $\| \cdot \|$ is the Lebesgue measure of a set and the random set
$$A_h = \{ x \in \mathcal{M}
: Y(x) > h\}$$
is called the {\em excursion set} above the threshold $h$. This approximation involves unknown $\mathbb{E} \|A_h\|$, which is the mean clump size of the excursion set. The distribution of $\|A_{h}\|$ has been estimated for the case of Gaussian \citep{aldous.1989}, $\chi^2 ,t$ and $F$ fields \citep{cao1999.AAP} but for general random fields, no approximation is available yet.

\section{Expected Euler Characteristics}

\index{multiple comparisons ! Euler characteristic method}
\index{Euler characteristics}

An alternate approximation to the supremum distribution based on the expected Euler characteristic (EC) of $A_h$ is also available. The Euler characteristic approach reformulates the geometric problem  as a topological problem. Read \citep{adler.1981, cao.2001, taylor.2007, worsley.2003} for an overview of the Euler characteristic method.

For sufficiently high threshold $h$, it is known that
\begin{eqnarray} P \Big(\sup_{x \in \mathcal{M}} Y(x) > h \Big) \approx \mathbb{E} \chi(A_h) = \sum_{d=0}^N
\mu_d(\mathcal{M})\rho_d(h)
\label{eq:deform-ECexpansion}
\end{eqnarray}
where $\mu_d(\mathcal{M})$ is the $d$-th
Minkowski functional or {\em intrinsic volume} of $\mathcal{M}$ and
$\rho_d$ is the $d$-th Euler characteristic (EC) density of
$Y$ \citep{worsley.1998}. For details on intrinsic volume, read \citep{schmidt.2005}. The expansion (\ref{eq:deform-ECexpansion}) also holds for non-isotropic fields but we will not pursue it any further.
Compared to other approximation methods such as the Poisson clump heuristic and the tube formulae, the advantage of using the Euler characteristic formulation is that a simple exact expression can be found for $\mathbb{E}\; \chi(A_h)$. Figure \ref{fig:power-euler} and Figure \ref{fig:power-eulerplot} show how $\chi(A_h)$ and $\mathbb{E}\; \chi(A_h)$ change as the threshold $h$ increases for a simple binary object with a hole.

\subsection{Intrinsic Volumes}
\index{intrinsic volumes}

The $d$-th intrinsic volume of $\mathcal{M}$ is a generalization of $d$-dimensional volume. Note that $\mu_0(\mathcal{M})$ is the Euler characteristic of $\mathcal{M}$.
$\mu_N(\mathcal{M})$ is the volume of $\mathcal{M}$ while $\mu_{N-1}(\mathcal{M})$ is half the surface area of $\mathcal{M}$. There are various techniques for computing the intrinsic volume \citep{taylor.2007}. The methods depend on the smoothness of the underlying manifold $\mathcal{M}$. For a solid sphere with
radius $r$, the intrinsic volumes are
$$\mu_0 =1, \mu_1 = 4r, \mu_2= 2 \pi r^2, \mu_3 = \frac{4}{3}\pi r^3.$$ For a 3D box of size $a \times b \times c$, the intrinsic volumes are
$$\mu_0=1, \mu_1= a+ b+c, \mu_2 = ab + bc + ac, \mu_3=abc.$$ In general, the intrinsic volume can be given in terms of a curvature matrix. Let $K_{\partial \mathcal{M}}$ be the curvature matrix of $\partial \mathcal{M}$ and $\text{detr}_{d}(K_{\partial \mathcal{M}}) $ be the sum of the determinant of all  $d \times d$ principal minors of $K_{\partial \mathcal{M}}$. For $d=0,\cdots,N-1$ the Minkowski functional $\mu_d(\mathcal{M})$ is defined as
$$\mu_d(\mathcal{M})=\frac{\Gamma(\frac{N-i}{2})}{2\pi^{\frac{N-i}{2}}}\int_{\partial \mathcal{M}} \text{detr}_{N-1-d}(K_{\partial \mathcal{M}}) \; dA,$$
and $\mu_N(\mathcal{M})=\|\mathcal{M}\|$, the Lebesgue measure of $\mathcal{M}$.

\begin{figure}[t]
\includegraphics[width=1\linewidth]{power-euler.pdf}
\centering
\caption{Gaussian white noise is added and smoothed to the key shaped binary object. The Euler characteristic of an object with a hole is 0.}
\label{fig:power-euler}
\end{figure}

For irregular jagged shapes such as the 2D corpus callosum shape $\mathcal{M}$,
the intrinsic volume can be estimated in the following
fashion \citep{worsley.1996.hbm, chung.2004.ni}. Treating pixels inside $\mathcal{M}$ as points on a lattice, let $V$ be the
number of vertices that forms the corners of pixels, $E$ be the number of edges connecting each adjacent lattice points and $F$ be the number of faces formed by four
connected edges. We assume the distance between the adjacent lattice points is $\delta$ in all directions. Then $$\mu_0=V - E + F, \mu_1=(E-2F)\delta, \mu_2= F\delta^2.$$  To find the number of edges and pixels
contained in $\mathcal{M}$, we start from an initial face (pixel) somewhere in  the corpus callosum and add one face at a time  while counting the additional edges and faces. In this fashion, we can grow a graph that will eventually contains all the pixels that form the corpus callosum. A numerical method for computing the intrinsic volume
for jagged irregular shapes has been implemented in FMRISTAT package (\url{www.math.mcgill.ca/keith/fmristat}).

\begin{figure}[t]
\includegraphics[width=0.8\linewidth]{power-eulerplot.pdf}
\centering
\caption{The mean Euler characteristic of the excursion sets of the shaped object shown in Figure \ref{fig:power-euler}. The number below each object is the threshold. \label{fig:power-eulerplot}}
\end{figure}

\subsection{Euler Characteristic Density}
\index{Euler characteristics}

The $d$-th EC-density is given by
$$\rho_d(h) = \mathbb{E} \big[(Y> h)\det( -\ddot{Y_d})|\dot{Y_d} = 0 \big]
P(\dot{Y_d}=0),$$ where dot notation indicates partial differentiation
with respect to the first $d$ components. The subscript $d$ represents the first $d$ components of $Y$. Computation of the
conditional expectation is nontrivial other than for Gaussian fields.
For zero mean and unit variance Gaussian field $Y$, we have for instance
\begin{eqnarray*} \rho_0 &=& P(Y > h) = 1 - \Phi(h)\\
\rho_1 &=& \lambda^{1/2}\frac{e^{-h^2/2}}{2\pi}\\
\rho_2 &=& \lambda h\frac{e^{-h^2/2}}{(2\pi)^{3/2}}\\
\rho_3 &=& \lambda^{3/2}(h^2-1) \frac{e^{-h^2/2}}{(2\pi)^2}, \end{eqnarray*}
where $\lambda$ measures the smoothness
of fields, defined as the variance of the derivative of component
of $Y$. The exact expression for the EC density $\rho_d$ is available for other random fields such as $t,\chi^2,F$ fields \citep{worsley.1994}, Hotelling's $T^2$ fields \citep{cao.1999.stat} and scale-space random fields \citep{siegmund.1996}. In each case, the EC density $\rho_d$ is proportional to $\lambda^{\frac{d}{2}}$ and it changes depending on the smoothness of the field.

If $X_1,\cdots,X_{\alpha}, Y_1,\cdots,
Y_{\beta}$ are i.i.d. stationary zero mean unit variance Gaussian fields. Then $F$-field with $\alpha$ and $\beta$ degrees of freedom is given by
$$F(x) = \frac{\sum_{j=1}^{\alpha} X_j^2(x)/\alpha}{\sum_{j=1}^{\beta} Y_j^2(x)/\beta}.$$
To avoid singularity, we need to assume the total degrees of
freedom $\alpha + \beta \gg N$ to be sufficiently larger than the
dimension of space \citep{worsley.1994}. The EC-density
for $F$-field is then given by \begin{eqnarray*} \rho_0 &=&\int_h^\infty {{\Gamma
({{\alpha + \beta}\over 2})}\over {\Gamma ({\alpha \over 2})\Gamma
({\beta \over 2})}} {\alpha\over \beta}\left({{\alpha x}\over
\beta }\right)^{(\alpha-2) \over 2} \left(1+{{\alpha x}\over \beta
}\right)^{-{(\alpha+\beta)\over 2}} d x,\\
\rho_1&=&\lambda^{1/2} {{\Gamma ({{\alpha+\beta-1}\over
2})2^{1\over 2}}\over{ \Gamma ({\alpha\over 2})\Gamma ({\beta
\over 2})}} \left({{\alpha h}\over \beta}\right)^{(\alpha-1) \over
2} \left(1+{{\alpha h}\over \beta}\right)^{-{(\alpha+\beta-2)\over
2}},\\
\rho_2&=&\frac{\lambda}{2\pi}{{\Gamma ({{\alpha +\beta-2}\over 2})}\over
{\Gamma ({\alpha \over 2})\Gamma ({\beta \over 2})}}
\left({{\alpha h}\over \beta }\right)^{(\alpha-2) \over 2}
\left(1+{{\alpha h}\over \beta }\right)^{-{(\alpha +\beta-2)\over 2}}\\
&\times&\left[(\beta -1){{\alpha h}\over \beta}-(\alpha-1)\right].\\
\end{eqnarray*}

If the random field $Y$ is given as the convolution of a smooth kernel $K_h(x)=K(x/h)/h^N$ with a white Gaussian noise \citep{siegmund.1996, worsley.1992}, the covariance matrix of $\dot Y= dY / dx$ is given by
$${\bf Var}(\dot Y) = \frac{\int_{\mathbb{R}^N}\dot K(\frac{x}{h}) \dot K^t(\frac{x}{h}) \;dx}{h^2\int_{\mathbb{R}^N} K^2(\frac{x}{h}) \; dx}.$$
Applying it to a Gaussian kernel $K(x)= (2\pi)^{-n/2}e^{-\|x\|^2/2}$ gives
$$ \lambda ={\bf Var}(\dot Y_1) = 1/(2h^2).$$ In terms of FWHM of the kernel $K_h$,
$$\lambda = 4\ln 2 /\text{FWHM}^2.$$

\subsection{Numerical Implementation of Euler Characteristics}
In this section, we show how to compute the expected Euler characteristic in {\tt MATLAB}. The presented routine can be used in estimating the excursion probability numerically. Consider a 2D binary object (Figure \ref{fig:power-euler}), which is stored as a 2D image {\tt toy-key.tif}. After loading the image using {\tt imread}, we perform scaling on image intensity values so that it becomes a binary object. The Euler characteristic of the binary object is then computed using {\tt bweuler}.

\begin{verbatim}
I=imread('toy-key.tif');
I= imresize(I,.1, 'nearest');
I=(max(max(I))-I);
I=I/max(max(I));
I=double(I);
figure;imagesc(I); colormap('hot')
eul = bweuler(I)

eul =

     0
\end{verbatim}
Since there is a hole in the object, the Euler characteristic is 0. We will add Gaussian white noise $N(0,0.5^2)$ to the binary object and smooth out with FWHM of 10 using {\tt gaussblur}. The resulting image is a Gaussian random field with sufficient smoothness. The smoothed image is stored as {\tt smooth} and displayed in Figure \ref{fig:power-euler}.
\begin{verbatim}
e=normrnd(0,1, 60, 37);
Y=I + e;
figure;imagesc(Y); colorbar; colormap('hot')
smooth = gaussblur(Y,10);
figure;imagesc(smooth);colorbar; colormap('hot');
\end{verbatim}
At each threshold {\tt h} between -1 and 1, we threshold {\tt smooth} and store it as a new variable {\tt excursion}. Then compute the Euler characteristic of {\tt excursion}. For computing the mean of the Euler characteristic, we simulated Gaussian random fields 50 times using the {\tt for}-loop.

\begin{verbatim}
figure;
eulsum=zeros(1,21);
for k=1:50
    Y=I+ normrnd(0,1,60,37);
    smooth = gaussblur(Y,10);
    eul=[];
    j=1;
    for h=-1:0.1:1
        [Yl, Yh] = threshold_image(smooth, h);
        Yh=reshape(Yh,60*37,1);
        excursion=zeros(60*37,1);
        excursion(find(Yh>h))=1;
        excursion=reshape(excursion, 60, 37);
        eul(j) = bweuler(excursion);
        j=j+1;
    end;
    hold on; plot(-1:0.1:1, eul, 'Color', [0.7 0.7 0.7])
    eulsum=eulsum+eul;
end;
hold on; plot(-1:0.1:1, eulsum/50, 'Color', 'k', 'LineWidth',2)
\end{verbatim}

\bibliographystyle{agsm}

Diffusion Equations for Medical Images