2

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!!!

3

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).

| improve this answer | |
  • Brilliant! Thanks also for explaining the reasoning! Very helpful. – learner Oct 7 '14 at 19:51
2

For issue 2 you have no ending \} (below is what you have)

\{ \textbf{G}$(x,y)$  if \textbf{W}$(x,y)\geq$ Mean(\textbf{W})

You are missing an ending \} Also, I would write this as:

$\mathbf{F}_{\mathbf{W}(x,y)} = \{\mathbf{G}(x,y)  \text{ if} \mathbf{W}(x,y)\geq \text{Mean}(\mathbf{W})\}$

This way you didn't have to enter math mode so many times.

For issue 3 (if you want bigger) use \displaystyle; that is, $\displaystyle\Sigma\Sigma

For issue 4 $\mathbf{Q} = \frac{\mathbf{I}}{w\mathbf{z}}$

For issue 1, is line numbering part of the package?

With algorithm2e not sure with just algorithm, you can do

{\LinesNumberedHidden
\begin{algorithm}
your stuff
\end{algorithm}}
| improve this answer | |
  • issue 1: I am not sure, just need them to be removed //// issue 2: please look at corresponding part of actual pseudocode. It has 2 equations inside one big curly brace. I want that. //// issue 3: \displaystyle still printing same small sigma //// issue 4: works now! – learner Oct 7 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.