From: Bjørn Rustad Date: Mon, 24 Mar 2014 08:26:00 +0000 (+0100) Subject: Blupp X-Git-Url: http://git.rustad.me/?a=commitdiff_plain;h=a8feefd3ec04aab5296064a5f6f58cddb04174ce;p=prosjektoppgave Blupp --- diff --git a/bib.bib b/bib.bib index 571b04e..435d504 100644 --- a/bib.bib +++ b/bib.bib @@ -157,4 +157,12 @@ publisher={MIT press} } +@book{scherzer2008variational, + title={Variational methods in imaging}, + author={Scherzer, Otmar and Grasmair, Markus and Grossauer, Harald and Haltmeier, Markus and Lenzen, Frank}, + volume={167}, + year={2008}, + publisher={Springer} +} + diff --git a/cut.tex b/cut.tex index 9f23628..33eebcb 100644 --- a/cut.tex +++ b/cut.tex @@ -100,28 +100,91 @@ equal to $\abs{f}$ for one of the minimal $s$-$t$-cuts in $G$. \fixme{But how do we find THE minimum cut? Which one do we want? The maximum one? The minimum one? EEEEK} +\fixme{Maximum vs maximal.} + \subsection{Augmenting flow algorithms} +The family of augmenting flow algorithms represent a popular approach to +the max flow problem. The idea is simply to look for paths from the +source to the sink in the graph, along which is is possible to send more +flow, and then send the maximum amount of flow along this path. When no +such path exists anymore, no more flow can be sent through the graph, +and maximum flow has been reached. +\begin{figure} + \centering +\begin{tikzpicture}[scale=1.5] + \node[vertex] (s) at (0, 0) {s}; + \node[vertex] (u) at (2, 1) {u}; + \node[vertex] (v) at (2, -1) {v}; + \node[vertex] (t) at (4, 0) {t}; + + \path[edge] (s) -- node[weight] {5/5} (u); + \path[selected edge] (s) -- node[weight] {} (v); + \path[edge] (s) -- node[weight] {0/5} (v); + \path[selected edge] (u) -- node[weight] {} (v); + \path[edge] (u) -- node[weight] {5/5} (v); + \path[selected edge] (u) -- node[weight] {} (t); + \path[edge] (u) -- node[weight] {0/5} (t); + \path[edge] (v) -- node[weight] {5/5} (t); +\end{tikzpicture} +\caption{A network with the flow and capacity shown as flow/capacity. +The marked path is a valid augmenting path from $s$ to $t$, and by +increasing the flow along it, we will push flow back from $v$ to +$u$. \fixme{refer to this figure somewhere?}} +\label{fig:aug_flow} +\end{figure} + +\subsubsection{Ford-Foulkerson} +The Ford-Foulkerson algorithm is the most basic augmenting flow +algorithm, which can be extended to more advanced algorithms. \begin{algorithm} \begin{algorithmic} \Function{Ford-Foulkerson}{$G$, $s$, $t$} \While{there exists a path $p$ from $s$ to $t$ in the residual network $G_f$} - \State $f \gets \min\{res(u, v) : (u, v) \in p \}$ + \State $\alpha \gets \min\{c_f(u, v) : (u, v) \in p \}$ \ForAll{$(u, v) \in p$} - \State $flow(u, v) \mathrel{+}= f$ - \State $flow(v, u) \mathrel{-}= f$ + \State $f(u, v) \mathrel{+}= \alpha$ + \State $f(v, u) \mathrel{-}= \alpha$ \EndFor \EndWhile \EndFunction \end{algorithmic} \caption{\sf The Ford-Foulkerson max-flow algorithm} \end{algorithm} +Of course, a choice has to be made on how to search for a path in the +residual network. A common choice is to do a breadth-first search from +the source node until the sink node is found, as this will yield the +shortest possible augmenting path. This version of the algorithm is +called Edmonds-Karp and has a running time of $O(VE^2)$. The reasoning +being that on each iteration, at least one edge disappears from the +residual network, and each edge can only disappear and reappear in the +residual network $O(V)$ times. This means that the number of loop +iterations is in $O(VE)$. Going through the edges in the augmenting path +takes $O(E)$ time, giving a total running time of $O(VE^2)$. A formal +proof can be found in \cite{cormen2009introduction}. +\fixme{Unneccesary hand-waving?} + +\fixme{HAVE TO REFER TO THE ALGORITHMS, THEY ARE FLOATING} +\fixme{Use res or $c_f$?} -\fixme{Use res or $c_f$???} +\subsubsection{Dinitz'} +\fixme{I did implement this, but it is maybe not very central to the +project/report.} \subsection{Graph representable energy functions} -Kolmogorov and Zabih define in \cite{kolmogorov2002energy} the class of -graph representable functions as follows +The next step is to find a way to create special graph such that we can +minimize the energy in (\fixme{should make an equation in the last +section I can reference}) using minimal graph cuts. We will do this by +constructing simple graphs representing the separate summands of the +energy function. For these small graphs it will be easy to verify that +the minimal cut also minimizes the energy function. These small graphs +can be added together giving a graph representing the complete energy +function of (\fixme{?}). + +First we need to establish the definition and result allowing us to +construct and add these special networks together. Kolmogorov and Zabih +define in \cite{kolmogorov2002energy} the class of graph representable +functions as follows \begin{definition}[Graph representable functions] Let $E(x_1, \hdots, x_n)$ be a function of $n$ binary variables. $E$ is graph-representable @@ -135,9 +198,25 @@ graph representable functions as follows \end{definition} From this definition we see that if we have a graph-representable function $E$ it is possible to find the exact global minimum of $E$ by -finding the minimal $s$-$t$-cut in the corresponding graph. +finding the minimal $s$-$t$-cut in the corresponding graph. + +Further they present an important result concerning what kinds of +functions are graph-representable +\fixme{Bad title} +\begin{theorem}[Identification of graph representable functions] + Given an energy function $E$ of $n$ binary variables on the form + \begin{equation} + E(x_1, \hdots, x_n) = \sum_i E^i(x_i) + + \sum_{i,fill] +\tikzstyle{bent edge} = [draw,bend left=80,thick,->] +\tikzstyle{double edge} = [draw,thick,<->] +\tikzstyle{weight} = [font=\small,sloped,fill=white] +\tikzstyle{weight noslope} = [font=\small,fill=white] +\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50] +\tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20] +\pgfdeclarelayer{background} +\pgfdeclarelayer{foreground} +\pgfsetlayers{background,main,foreground} + \newtheorem{theorem}{Theorem} \newtheorem{definition}{Definition} diff --git a/total.tex b/total.tex index 0da5459..505c645 100644 --- a/total.tex +++ b/total.tex @@ -21,11 +21,23 @@ our case an open subset of $\mathbb{R}^2$. Normally, $p$ is chosen to be 1 or 2. \subsection{Probabilistic background} -The model can be grounded on spatial statistics by introducing -and maximizing the likelihood $p(u \mid v) \cdot p(u)$. This is -equivalent to the formulation +\fixme{We discuss pixels here already?} +\fixme{The actual expression for the total variation has not been +introduced yet!} + +Image processing is pushing forward in many fields at once, analysis, +spatial statistics and discrete optimization to name a few. Methods can +often be related across fields, and in this short section we will see +how the total variation method can be related to one instance of the +so-called maximum a posteriori estimation (MAP for short) of spatial +statistics. + +We introduce the likelihood $p(u \mid v) \cdot p(u)$ and try to maximize +this in order to obtain our output image $u$. This is equivalent to the +formulation \begin{equation} \min_u \big( - \ln p(u \mid v) - \ln p(u) \big). + \label{eq:minimize_neg_log} \end{equation} If the noise term $p(u \mid v)$ is modeled to be independently and identically distributed Gaussian noise on each pixel, we have @@ -33,9 +45,27 @@ identically distributed Gaussian noise on each pixel, we have p(u \mid v) \propto \prod_x \exp \left(-\frac{(u_x - v_x)^2}{2\sigma^2} \right). \end{equation} -Taking the logarithm we obtain +The prior $p(u)$ represents how probable we think it is to obtain an +image like $u$. This probability depends on what kinds of images are +considered, and how they are obtained. In the theory of Markov random +fields, one lets the probability of a pixel value depend only on some +neighborhood $\mathcal{N}$. One common choice for the relation between +neighboring pixels is a Laplace distribution +\begin{equation} + p(u) \propto + \prod_x \prod_{y \in \mathcal{N}(x)} \exp \left( + - \frac{\abs{u_x - u_y}}{b} + \right). +\end{equation} +Consult for example \cite{scherzer2008variational} for further reading +on different possibilities for the prior probability. + +Taking the logarithm in \eqref{eq:minimize_neg_log} we obtain \begin{equation} - \min_u \left( \sum_x \abs{u_x - v_x}^2 - \beta \ln p(u) \right). + \min_u \left( + \sum_x \abs{u_x - v_x}^2 + - \beta \sum_x \sum_{y \in \mathcal{N}(x)} \abs{u_x - u_y} + \right). \label{eq:minimizing_probability} \end{equation} If the noise had been modeled with the Laplace distribution @@ -188,20 +218,17 @@ one-dimensional image divided into its level sets. \centering \begin{subfigure}[b]{0.4\textwidth} \centering - \begin{tikzpicture}[->,thick,font=\footnotesize, - main node/.style={circle,draw,minimum size=.7cm}] - - \node[main node] (x) at (0, 0) {x}; - \node[main node] (2) at (-2, 0) {}; - \node[main node] (3) at ( 2, 0) {y}; - \node[main node] (4) at (0, -2) {}; - \node[main node] (5) at (0, 2) {}; + \begin{tikzpicture}[scale=1] + \node[vertex] (x) at (0, 0) {x}; + \node[vertex] (y) at (2, 0) {y}; + \node[vertex] (a) at (0, 2) {}; + \node[vertex] (b) at (0, -2) {}; + \node[vertex] (c) at (-2, 0) {}; - \path - (x) edge node {} (2) - (x) edge node [above] {$w_{xy}$} (3) - (x) edge node {} (4) - (x) edge node {} (5); + \path[edge] (x) -- (y); + \path[edge] (x) -- (a); + \path[edge] (x) -- (b); + \path[edge] (x) -- (c); \end{tikzpicture} \caption{Size four neighborhood.} \label{fig:c4_grid} @@ -265,10 +292,11 @@ anisotropically as follows \label{eq:tv_discrete_int} \end{equation} where the second sum is over nodes in a neighborhood relation and the -$w_{uv}$ is the weight of this relation. Intuitively, the perimeter of +$w_{xy}$ is the weight of this relation. Intuitively, the perimeter of the level set $u^\lambda$ is proportional to the number of edges crossing this perimeter, as $\abs{u^\lambda_x - u^\lambda_y}$ only contributes to the sum when one node is 0 and the other is 1. +\fixme{Describe what this sum over $(x,y)$ is actually over.} The sum only goes up to the level $L-2$ since $u^{L-1}$ is constant equal to 1 in every pixel of the image. Figure @@ -343,12 +371,40 @@ Using this we rewrite \eqref{eq:norm_discrete_int} and obtain (1 - u^\lambda_x) + N_x(0) \end{equation} We have now discretized the energy function and decomposed it into a sum -over all the levels $\lambda$ of the image. If we minimize each level -separately it is obvious that we also minimize the total energy. The -question is if the obtained level sets $u^\lambda$ can be combined to -make an output image. The level sets were defined as $u^\lambda = -\mathbbm{1}_{u \leq \lambda}$, so we need them to be monotonely -increasing in increasing level values, i.e.\ +over all the levels $\lambda$. Ignoring the constant term $N_x(0)$ we +are left with +\begin{equation} + E_v(u) = + \sum_{\lambda=0}^{L-2} \sum_x E^x(u^\lambda_x) + + \beta \sum_{\lambda = 0}^{L-2} \sum_{x < y} E^{x,y}(u^\lambda_x, + u^\lambda_y) +\end{equation} +where +\begin{align} + E^x(u^\lambda_x) &= + \big( + N_x(\lambda + 1) - + N_x(\lambda) + \big) + (1 - u^\lambda_x) + \label{eq:fidelity_energy} \\ + E^{x,y}(u^\lambda_x, u^\lambda_y) &= + w_{xy} + \left( + \left(1 - 2 u_y^\lambda \right) u_x^\lambda + u_y^\lambda + \right). + \label{eq:neigh_energy} +\end{align} +In the sum of the energy between neighboring pixels, we consider only +relations where $x < y$ since the term \eqref{eq:neigh_energy} is +symmetric. The factor of $2$ which appears when combining the terms is +absorbed into the $\beta$ parameter. + +If we minimize each level separately it is obvious that we also minimize +the total energy. The question is if the obtained level sets $u^\lambda$ +can be combined to make an output image. The level sets were defined as +$u^\lambda = \mathbbm{1}_{u \leq \lambda}$, so we need them to be +monotonely increasing in increasing level values, i.e.\ \begin{equation} u^\lambda_x \leq u^\mu_x \quad \forall \lambda \leq \mu, \quad \forall x \in S.