[Tex/LaTex] Complicated Pseudocode in Latex – Need assistance

algorithmicxpseudocode

I am trying to create a complicated pseudocode as shown below:

image

My attempt:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}

\begin{algorithm}
  \caption{Self-Quotient algorithm}\label{euclid}

  \begin{algorithmic}[1]
  %-------------- Input & Output -----------------
  \State \textbf{Input:} Input image \textbf{I}, Gaussian filter \textbf{G} of size \textit{s}$\times$\textit{s}
  \State \textbf{Output:} Self-Quotient image \textbf{Q}

  %--------------- for loop -----------------------
  \For{\textbf{all} pixel \textbf{I}$(x,y)$}
       \State Consider a window \textbf{W} of size s$\times$s around \textbf{I}$(x,y)$
       \State Compute the anisotropic filter $\textbf{F}_{\textbf{W}(x,y)}$ at the location $(x,y)$

       \State $\textbf{F}_{\textbf{W}(x,y)}$ = \{ \textbf{G}$(x,y)$  if \textbf{W}$(x,y)\geq$ Mean(\textbf{W})
       \State $\textbf{Z}(x,y)$ = $\Sigma\Sigma( \textbf{F}_{\textbf{W}(x,y)} \circ \textbf{W}(x,y) )$
       \State Compute the weight \textbf{w}
       \State \textit{w} = ( \textit{s} $\times$ \textit{s} ) $\times \Sigma\Sigma \textbf{F}_\textbf{W}$
  \EndFor

  %----------- Remaining text ----------------
  \State Compute Self-Quotient image \textbf{Q} and correct singularities
  \State \textbf{Q} = 
  \State Adjust histogram and normalize image \textbf{Q}

  \end{algorithmic}
\end{algorithm}
\end{document}

This is the output:

I am not able to do a few things:

  1. Remove line numbers on the left

  2. curly braces in line 6: statement incomplete

  3. size of Sigma in line 7 not like what I want. Also line 9 same problem.

  4. creating the 2nd-last line (line 12)

Could someone please fix this? I have tried a lot!!!

Best Answer

The following provides the output that you want:

enter image description here

\documentclass{article}
\usepackage{algorithm,amsmath,algpseudocode}
\begin{document}

\begin{algorithm}
  \caption{Self-Quotient algorithm}\label{euclid}

  \begin{algorithmic}[0]
  %-------------- Input & Output -----------------
  \State \textbf{Input:} Input image \textbf{I}, Gaussian filter \textbf{G} of size \textit{s}$\times$\textit{s}
  \State \textbf{Output:} Self-Quotient image \textbf{Q}

  %--------------- for loop -----------------------
  \For{\textbf{all} pixel $\textbf{I}(x,y)$}
       \State Consider a window \textbf{W} of size $s \times s$ around $\textbf{I}(x,y)$
       \State Compute the anisotropic filter $\textbf{F}_{\textbf{W}(x,y)}$ at the location $(x,y)$

       \State $\textbf{F}_{\text{\textbf{W}(x,y)}} = \left\{\begin{array}{cl}
           \textbf{G}(x,y) & \text{if $\textbf{W}(x,y) \geq \text{Mean}(\textbf{W})$} \\
           0               & \text{if $\textbf{W}(x,y) < \text{Mean}(\textbf{W})$}
         \end{array}\right.$
       \State $\textbf{Z}(x,y)$ = $\sum\sum ( \textbf{F}_{\text{\textbf{W}(x,y)}} \circ \textbf{W}(x,y) )$
       \State Compute the weight $w$
       \State $w = ( s \times s ) \times \sum\sum \textbf{F}_{\text{\textbf{W}}}$
       \State $w = \tfrac{1}{w}$
  \EndFor

  %----------- Remaining text ----------------
  \State Compute Self-Quotient image \textbf{Q} and correct singularities
  \State $\textbf{Q} = \tfrac{\textbf{I}}{w\textbf{Z}}$
  \State Adjust histogram and normalize image \textbf{Q}

  \end{algorithmic}
\end{algorithm}
\end{document}

Regarding your outstanding issues, here are the remedies:

  1. Use \begin{algorithmic}[0];

  2. Use \left\{\begin{array}{cl} ... \end{array}\right. or the cases environment supplied by amsmath;

  3. Use \sum, not \Sigma;

  4. Use \frac{<numerator>}{<denominator>} or \tfrac (also from amsmath).

Related Question