我正在尝试创建一个复杂的伪代码,如下所示:
我的尝试:
\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}
这是输出:
我无法做以下几件事:
删除左侧的行号
第 6 行的花括号:语句不完整
第 7 行的 Sigma 大小不符合我的要求。第 9 行也有同样的问题。
创建倒数第二行(第 12 行)
有人能修复这个问题吗?我试了很多次了!!!
答案1
以下提供您想要的输出:
\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}
针对您尚未解决的问题,补救措施如下:
答案2
对于第 2 期,您没有结局\}
(以下是您所拥有的)
\{ \textbf{G}$(x,y)$ if \textbf{W}$(x,y)\geq$ Mean(\textbf{W})
你缺少一个结尾\}
另外,我会这样写:
$\mathbf{F}_{\mathbf{W}(x,y)} = \{\mathbf{G}(x,y) \text{ if} \mathbf{W}(x,y)\geq \text{Mean}(\mathbf{W})\}$
这样您就不必多次进入数学模式。
对于问题 3(如果您想要更大),使用\displaystyle
;即$\displaystyle\Sigma\Sigma
对于第 4 期$\mathbf{Q} = \frac{\mathbf{I}}{w\mathbf{z}}$
对于问题 1,行号是软件包的一部分吗?
不确定algorithm2e
,algorithm
你可以做
{\LinesNumberedHidden
\begin{algorithm}
your stuff
\end{algorithm}}