Re: Algorithmicx, equation e split

#87131
Up
0
Down
::


ok controllando il sorgente pare che si sia un blocco non chiuso in un altro algoritmo. Posto un MWE, è lungo e diviso in due sezioni. Rileggendo non sono stato in grado di capire cosa ho lasciato aperto (:oops: ). Se qualcuno avesse voglia/tempo di buttarci un occhio sarebbe gesto molto apprezzato. Grazie.

`\documentclass{article}
\usepackage{amsmath,amsfonts,algorithm,algpseudocode}

\begin{document}

\begin{algorithm}[!h]
\caption{Vincent-Soille watershed algorithm}\label{wshedPseudocode}
\small
\begin{algorithmic}[1]
\Procedure{Watershed-by-Immersion}{}
\Require{digital grey scale image $G = (D,E,im)$}
\Ensure{labelled watershed image \textit{lab} on $D$}
\State{\# define \textsc{init} -1 } \Comment{initial value of $lab$ image}
\State{\# define \textsc{mask} -2 } \Comment{initial value of each level}
\State{\# define \textsc{wshed} 0 } \Comment{label of watershed pixel}
\State{\# define \textsc{fictitious} (-1,-1) } \Comment{fictitious pixel $\notin D$}
\State$curlab \gets 0$ \Comment{$curlab$ is the current label}
\State$fifo\_init(queue)$
\For{\textbf{all} $p \in D$}
\State $lab\lbrack p \rbrack \gets \textsc{init}; dist\lbrack p \rbrack \gets 0$ \Comment{$dist$ is a work image of distances}
\EndFor
\State{SORT pixels in increasing order of grey values from $h_{min}$ to $h_{max}$}
\State
\State{Start Flooding}
\For{$h = h_{min}$ to $h_{max}$} \Comment{Geodesic SKIZ of level $h-1$ inside level $h$}
\For{\textbf{all} $p \in D$ \textbf{with} $im\lbrack p\rbrack = h$} \Comment{mask all pixel at level h, these are directly accessible because of the sorting step}
\State{$lab\lbrack p \rbrack \gets \textsc{mask}$ }
\If{$p$ has a neighbour $q$ \textbf{with} ($lab \lbrack q \rbrack = \textsc{wshed}$)}
\Comment{Initialize queue with neighbours at level $h$ of current basins or watersheds}
\State $dist\lbrack p \rbrack \gets 1; fifo\_add(p,queue)$
\EndIf
\EndFor
\State$curdist \gets 1; fifo\_add(\textsc{fictitious},queue)$

\Loop \Comment{extend basins}
\State $p \gets fifo\_remove(queue)$
\If {$p = \textsc{fictitious}$}
\If {$ fifo\_empty(queue)$}
\State{\textsc{break}}
\Else
\State $fifo\_add(\textsc{fictitious},queue $)
\State $curdist \gets curdist +1 $
\State $ p \gets fifo\_remove(queue)$
\EndIf
\EndIf

\For{\textbf{all} $q \in N_G(p)$}\Comment{labelling $p$ by inspecting neighbours}
\If{$dist\lbrack q \rbrack < curdist$ \textbf{and} $lab\lbrack q \rbrack > 0$ \textbf{or} $lab\lbrack q \rbrack > \textsc{wshed}$}
\State{$q$ belongs to an existing basin or watershed}
\algstore{bkbreak}
\end{algorithmic}
\end{algorithm}
\clearpage
\begin{algorithm}[!h]
\begin{algorithmic}[1]
\algrestore{bkbreak}

\If{$lab\lbrack q \rbrack > 0$}
\If{$lab\lbrack p \rbrack = \textsc{mask}$ \textsc{or} $lab\lbrack p \rbrack > \textsc{wshed}$}
\State $lab\lbrack p \rbrack \gets lab\lbrack q \rbrack $
\ElsIf{$lab\lbrack p \rbrack \neq lab\lbrack q \rbrack $}
\State $lab\lbrack p \rbrack \gets \textsc{wshed} $
\EndIf
\ElsIf{$lab\lbrack p \rbrack = \textsc{mask} $}
\State$lab\lbrack p \rbrack \gets \textsc{wshed} $
\EndIf
\ElsIf{$lab\lbrack q \rbrack = \textsc{mask}$ \textsc{and} $dist\lbrack q \rbrack = 0$} \Comment{$q$ is a plateau pixel}
\State$dist\lbrack q \rbrack \gets curdist + 1; fifo\_add(1,queue)$
\EndIf
\EndFor
\EndLoop
\State{detect and process new minima at level $h$}
\For{\textbf{all} $p \in D$ \textbf{with} $im \lbrack p \rbrack = h$}
\State$dist \lbrack p \rbrack = 0$ \Comment{reset distance to zero}
\If{$lab\lbrack p \rbrack = \textsc{mask}$} \Comment{$p$ is inside a new minimum}
\State{$curlab \gets curlab +1$} \Comment{create a new label}
\State{$fifo\_add(p,queue);lab\lbrack p \rbrack \gets curlab$}
\While{\textbf{not} $fifo\_empty(queue)$}
\State{$q \gets fifo\_remove(queue)$}
\For{\textbf{all} $r \in N_G(q)$}\Comment{inspect neighbours of $q$}
\If{$lab\lbrack r \rbrack = \textsc{mask}$}
\State{$fifo\_add(r,queue); lab\lbrack r \rbrack \gets curlab$}
\EndIf
\EndFor
\EndWhile
\EndIf
\EndFor
\EndFor
\State{End Flooding}
\end{algorithmic}
\end{algorithm}
\end{document}`

Go to top