]> git.rustad.me Git - prosjektoppgave/commitdiff
Blupp
authorBjørn Rustad <bjorn@rustad.me>
Mon, 24 Mar 2014 08:26:00 +0000 (09:26 +0100)
committerBjørn Rustad <bjorn@rustad.me>
Mon, 24 Mar 2014 08:26:00 +0000 (09:26 +0100)
bib.bib
cut.tex
main.tex
total.tex

diff --git a/bib.bib b/bib.bib
index 571b04e5b3ecff47c5c3daf444a93d7b2dad1b5f..435d504deef42dbc2d3036009a0d8b7ea1b6cb0e 100644 (file)
--- a/bib.bib
+++ b/bib.bib
        publisher={MIT press}\r
 }\r
 \r
+@book{scherzer2008variational,\r
+       title={Variational methods in imaging},\r
+       author={Scherzer, Otmar and Grasmair, Markus and Grossauer, Harald and Haltmeier, Markus and Lenzen, Frank},\r
+       volume={167},\r
+       year={2008},\r
+       publisher={Springer}\r
+}\r
+\r
 </bibtex>\r
diff --git a/cut.tex b/cut.tex
index 9f23628927804493acbd1efc56411d43b46d031f..33eebcb712c10e33669ff4190531aab041df2326 100644 (file)
--- 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<j} E^{i,j}(x_i, x_j),
+    \end{equation}
+    then $E$ is graph representable if and only if each term $E^{i,j}$
+    satisfies the inequality
+    \begin{equation}
+        E^{i,j}(0,0) + E^{i,j}(1,1) \leq E^{i,j}(0,1) + E^{i,j}(1,0).
+    \end{equation}
+\end{theorem}
 
-The following theorem if proved by Kolmogorov and Zabih in
+The following theorem proved by Kolmogorov and Zabih in
 \cite{kolmogorov2002energy} and will be crucial in our graph
 construction.
 \begin{theorem}[Additivity]
@@ -146,12 +225,108 @@ construction.
     $V = \cup_k V^k$ and $E = \cup_k E^k$ and the capacities $c(u,v)
     = \sum_k c^k(u,v)$.
 \end{theorem}
-It will allow us to construct simple graphs which represents the
-different summands of \fixme{(?????)} and add them together to create
-our final graph.
+It allows us to construct simple graphs representing the different
+summands of \fixme{(?????)} and add them together to create our final
+graph.
+
+\subsection{Graph construction}
+For our neighboring relation in (\fixme{ref}) on the form
+\begin{equation}
+    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).
+\end{equation}
+we have
+\begin{equation}
+\begin{aligned}
+    E^{x,y}(0, 0) &= w_{x,y} \cdot 0, \\
+    E^{x,y}(0, 1) &= w_{x,y} \cdot 1, \\
+    E^{x,y}(1, 0) &= w_{x,y} \cdot 1, \\
+    E^{x,y}(1, 1) &= w_{x,y} \cdot 0,
+\end{aligned}
+\label{eq:neigh_energies}
+\end{equation}
+and by theorem (\fixme{ref}) our energy function is graph representable.
+Kolmogorov and Zabih presents a way to construct a graph for any graph
+representable function in \cite{kolmogorov2002energy}. Since our
+energies in \eqref{eq:neigh_energies} are especially simple, the
+construction and presentation is simplified.
+\begin{figure}
+    \centering
+\begin{tikzpicture}[scale=1.5]
+     \node[vertex] (s) at (0, 0) {s};
+     \node[vertex] (u) at (-1,-2) {u};
+     \node[vertex] (v) at (1, -2) {v};
+     \node[vertex] (t) at (0, -4) {t};
+
+     \path[edge] (s) -- node[weight] {$w_{x,y}$} (u);
+     \path[edge] (u) -- node[weight] {$2w_{x,y}$} (v);
+     \path[edge] (v) -- node[weight] {$w_{w,y}$} (t);
+\end{tikzpicture}
+\caption{\fixme{Why can't we subtract $w_{x,y}$ from the whole graph
+here? AND CHOOSE u v or x y....}
+\label{fig:neigh_subgraph}
+\end{figure}
+
+\begin{figure}
+    \centering
+\begin{tikzpicture}[scale=2.0]
+     \node[vertex] (s) at (0,  0) {s};
+     \node[vertex] (u) at (0, -1) {u};
+     \node[vertex] (t) at (0, -2) {t};
+
+     \path[edge] (s) -- node[weight noslope] {$E^u(0)$} (u);
+\end{tikzpicture}
+\caption{Something something $E^u(0)$ is always positive and $E^u(1)$ is
+always zero.}
+\label{fig:norm_subgraph}
+\end{figure}
+
+\fixme{Make it clear what happens when a node lands on the $T$-side
+versus the $S$-side.}
 
 \fixme{Graph is usually called network when we are talking about flow.}
 
+\begin{figure}
+    \centering
+\begin{tikzpicture}[scale=1.3]
+    \begin{scope}[
+            yshift=-100,every node/.append style={
+            yscale=.3,yslant=.4,xslant=-0.6},yscale=.3,yslant=.4,xslant=-0.6
+        ]
+        \foreach \x in {0,...,3} {
+            \foreach \y in {0,...,3} {
+                \node[vertex] (\x\y) at (\x, \y) {};
+            }
+        }
+        \foreach \x in {0,...,3} {
+            \foreach \y [count=\yi] in {0,...,2} {
+                \path[double edge] (\x\y)--(\x\yi);
+                \path[double edge] (\y\x)--(\yi\x);
+            }
+        }
+    \end{scope}
+
+    \node[vertex] (s) at (1, 0) {s};
+    \node[vertex] (t) at (1, -5) {t};
+
+    \begin{pgfonlayer}{background}
+    \foreach \x in {0,...,3} {
+        \foreach \y in {0,...,3} {
+            \path[edge] (s) to (\x\y);
+            \path[edge] (\x\y) to (t);
+        }
+    }
+    \end{pgfonlayer}
+\end{tikzpicture}
+\caption{HELLO}
+\label{fig:image_flow}
+\end{figure}
+
+\fixme{DISREGARD THIS $\downarrow$}
+
 \subsubsection{Dinic's algorithm}
 The «best» of the augmenting-path algorithms (citation needed). Makes a
 level graph with BFS, and finds a blocking flow through this graph which
index 46ab8327ea14e062ebb80b832c5dfa85dc9fb176..9fae3a8ae1c83d31c5f7183c42bee08107d80f56 100644 (file)
--- a/main.tex
+++ b/main.tex
 \usepackage{bbm}                      % Indicator function \mathbbm{1}
 \usepackage{caption}
 \usepackage{subcaption}
+\usepackage{xfrac}
 
 \usepackage{algorithm}
 \usepackage{algpseudocode}
 
+\tikzstyle{vertex}=[circle,minimum size=20pt,inner sep=0pt,draw]
+\tikzstyle{selected vertex} = [vertex, fill=red!24]
+\tikzstyle{edge} = [draw,thick,->,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}
                                  
index 0da54591ff0ffdf1938afee3acd48c938cc4340b..505c64511cb89cfd25ec71b2d004938a8095314c 100644 (file)
--- 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.