12

I need to draw the following diagram using TikZ package in LaTeX

enter image description here

I wrote the following code so far:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
    \begin{tikzpicture}[auto, node distance=2cm,>=latex']
        \tikzstyle{block} = [draw, rectangle];
        \tikzstyle{rblock}=[draw, shape=rectangle,rounded corners=0.5em];
        \node [rblock] (start) {Start};
        \node [block, right of=start] (acquire) {Acquire Image};
        \node [block, right of=acquire] (rgb2gray) {RGB to Gray};
        \node [block, right of=rgb2gray] (otsu) {Localized OTSU Thresholding};
        \node [block, below of=otsu] (gchannel) {Subtract the Green Channel};
        \node [block, left of=gchannel] (closing) {Morphological Closing};
    \end{tikzpicture}
\end{document}

But the result I get is really bad and all the boxes are on top of each other. Please note, in my code "Subtract the Green Channel" node is below "Localized Otsu Thresholding" but that is also fine, flow diagram can flow either way but preferably the one shown in image.

Could someone please tell me what I'm missing? How can I fix the length of box and let text within them span multiple lines? If possible an someone provide me LaTeX code that could draw flow diagram as shown in image? Any help would be appreciated.

Thanks everyone who answered. I've got this far:

Progress so far

The code I used is below:

\begin{tikzpicture}[>=latex']
    ikzset{block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
    rblock/.style={draw, shape=rectangle,rounded corners=1em,align=left,minimum width=1.5cm,minimum height=0.75cm},
    input/.style={ % requires library shapes.geometric                                                                                                                                                                                         
      draw,
      trapezium,
      trapezium left angle=60,
      trapezium right angle=120,
      minimum width=2.0em,
      align=center,
      minimum height=1.5em
    },
  }


\node [rblock] (start) {Start};  
\node [block, right =1.75em of start] (acquire) {Acquire Image};

\node [block, right =1.75em of acquire] (rgb2gray) {RGB to Gray};
\node [block, below =1.75em of rgb2gray.south] (otsu) {Localized OTSU \\ Thresholding};
\node [block, left =1.75em  of otsu] (gchannel) {Subtract the Green \ Channel};
\node [block, below left =1.75em of gchannel] (closing) {Morphological \\ Closing};
\node [block, right =1.75em of closing] (NN) {Sign Detection \\ Using NN};
\node [input, right  =1.75em of NN] (limit) {Speed \\ Limit};
\node [coordinate, right =1em of otsu.east] (otsu_right) {};  %% Coordinate on right and middle                                                                                                                                              

  %% paths                                                                                                                                                                                                                                     
  \path[draw,->] (start) edge (acquire)
  (acquire) edge (rgb2gray)
  (rgb2gray.east) -| (otsu_right) -- (otsu.east)
  (otsu) edge  (gchannel)
%  (gchannel) edge (closing)                                                                                                                                                                                                                   
%  (closing) edge (NN)                                                                                                                                                                                                                         
%  (NN) edge (limit)                                                                                                                                                                                                                           
  ;
\end{tikzpicture}

I'm using two column paper style therefore you fit things in, I've putting less number of boxes each line. I want that RGB to Gray node should be right aligned with Localized OTSU node and Morphological opening node left aligned with Subtract Green Channel node. I Please help. Thanks!

3

2 Answers 2

15

You can use positioning library and a useful reading will be this question. Further, tikzstyle is deprecated, use tikzset instead.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}
\begin{document}
    \begin{tikzpicture}[>=latex']
        \tikzset{block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
        rblock/.style={draw, shape=rectangle,rounded corners=1.5em,align=center,minimum width=2cm,minimum height=1cm},
        input/.style={ % requires library shapes.geometric
        draw,
        trapezium,
        trapezium left angle=60,
        trapezium right angle=120,
        minimum width=2cm,
        align=center,
        minimum height=1cm
    },
        }
        \node [rblock]  (start) {Start};
        \node [block, right =2cm of start] (acquire) {Acquire Image};
        \node [block, right =2cm of acquire] (rgb2gray) {RGB to Gray};
        \node [block, right =2cm of rgb2gray] (otsu) {Localized OTSU \\ Thresholding};
        \node [block, below right =2cm and -0.5cm of start] (gchannel) {Subtract the \\ Green Channel};
        \node [block, right =2cm of gchannel] (closing) {Morphological \\ Closing};
        \node [block, right =2cm of closing] (NN) {Sign Detection \\ Using NN};
        \node [input, right =2cm of NN] (limit) {Speed \\ Limit};
        \node [coordinate, below right =1cm and 1cm of otsu] (right) {};  %% Coordinate on right and middle
        \node [coordinate,above left =1cm and 1cm of gchannel] (left) {};  %% Coordinate on left and middle

%% paths
        \path[draw,->] (start) edge (acquire)
                    (acquire) edge (rgb2gray)
                    (rgb2gray) edge (otsu)
                    (otsu.east) -| (right) -- (left) |- (gchannel)
                    (gchannel) edge (closing)
                    (closing) edge (NN)
                    (NN) edge (limit)
                    ;
    \end{tikzpicture}
\end{document}

enter image description here

4
  • Thanks for the answer. Can you tell me how can I bring start at extreme left?
    – Shivam
    Commented Dec 12, 2013 at 0:42
  • @ShivamKalra use \node [block, below right =2cm and -0.5cm of start] (gchannel) {Subtract the \\ Green Channel}; Use appropriate length for -0.5cm in below right =2cm and -0.5cm
    – user11232
    Commented Dec 12, 2013 at 0:48
  • @Harrish Many thanks for answer. Please check my edits above.
    – Shivam
    Commented Dec 12, 2013 at 1:44
  • @HarishKumar I am sorry, but how can I edit this line (otsu.east) -| (right) -- (left) |- (gchannel) to connect between (otsu.south) and (gchannel.north) in down-left-down way?
    – Diaa
    Commented Jun 4, 2016 at 18:23
6

As already mentioned Torbjørn, your problem is wrong use of right of = (deprecated use) and absent of library positioning. I suppose, that you like to achieve something like example below:

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes}
\begin{document}
    \begin{tikzpicture}[node distance=1cm,>=latex',
 block/.style = {draw, shape=rectangle, align=center},
rblock/.style = {draw, shape=rectangle, rounded corners=0.5em},
tblock/.style = {draw, shape=trapezium, trapezium left angle=60, 
                 trapezium right angle=120, align=center},
                        ]
\linespread{0.9}
    \node [rblock]                      (start)     {Start};
    \node [block, right=of start]       (acquire)   {Acquire Image};
    \node [block, right=of acquire]     (rgb2gray)  {RGB to Gray};
    \node [block, right=of rgb2gray]    (otsu)      {Localized OTSU\\ Thresholding};
    \node [block, below=of acquire]     (gchannel)  {Subtract the\\ Green Channel};
    \node [block, right=of gchannel]    (closing)   {Morphological\\ Closing};
    \node [block, right=of closing]     (detecting) {Sign Detectiing\\ using NN};
    \node [tblock, right=of detecting]  (speed)     {Speed\\ Limit};
\draw[->] (start) -- (acquire);
\draw[->] (acquire) -- (rgb2gray);
%etc
    \coordinate[below right=5mm and 5mm of otsu]   (a1);
    \coordinate[left=5mm of a1 -| gchannel.west]   (a2);
\draw[->] (otsu) -| (a1) -- (a2) |- (gchannel);
%etc
    \end{tikzpicture}
\end{document}

below is possible variant of desired flowchart (after your editing of question). i hope, that from all provided examples you will be able catch the principle, how to draw your flowchart. if you still have problems with width of picture, tray to use smaller fonts and schrink minimum width of boxes ...

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes}
\begin{document}
    \begin{tikzpicture}[node distance=4mm, >=latex',
 block/.style = {draw, rectangle, minimum height=10mm, minimum width=28mm,align=center},
rblock/.style = {draw, rectangle, rounded corners=0.5em},
tblock/.style = {draw, trapezium, minimum height=10mm, 
                 trapezium left angle=75, trapezium right angle=105, align=center},
                        ]
    \node [rblock]                      (start)     {Start};
    \node [block, right=of start]       (acquire)   {Acquire Image};
    \node [block, right=of acquire]     (rgb2gray)  {RGB to Gray};
    \node [block, below=of rgb2gray]    (otsu)      {Localized OTSU\\ Thresholding};
    \node [block, below=of acquire]     (gchannel)  {Subtract the\\ Green Channel};
    \node [block, below=of gchannel]    (closing)   {Morphological\\ Closing};
    \node [block, right=of closing]     (detecting) {Sign Detecting\\ using NN};
    \node [tblock, right=of detecting]  (speed)     {Speed\\ Limit};
%% paths (borowed from Harish Kumar)
    \path[draw,->] (start)      edge (acquire)
                   (acquire)    edge (rgb2gray)
                   (rgb2gray)   edge (otsu)
                   (otsu)       edge (gchannel)
                   (gchannel)   edge (closing)
                   (closing)    edge (detecting)
                   (detecting)  edge (speed)
                    ;
    \end{tikzpicture}
\end{document}

enter image description here

2
  • You can add an image to see the output too.
    – osjerick
    Commented Dec 11, 2013 at 23:58
  • Please check my edits above.
    – Shivam
    Commented Dec 12, 2013 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .