I would like to implement the following pictorial representation of array using TikZ/Latex.
Please provide some hints to go in the right direction.
tikz-pgf
I would like to implement the following pictorial representation of array using TikZ/Latex.
Please provide some hints to go in the right direction.
You can start with the Asymptote
, which is included in TeXLive 2012
but can be used with other distributions as well.
It is able to handle both vector and raster graphics.
Following example gblur.asy
file
(which can be improved in many ways) draws a color matrix and then
applies a Gaussian filter matrix (from the wiki) to it once and twice:
size(200);
real[][] gFilt={
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771},
{0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117},
{0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292},
{0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067},
};
import pm;
import palette;
pen[][] matrix2pen(triple[][] pm){
int n=pm.length;
triple t;
pen[][] v=new pen[n][n];
for(int i=0; i < n; ++i){
for(int j=0; j < n; ++j){
t=pm[n-1-j][i];
v[i][j]=rgb(t.x/255,t.y/255,t.z/255);
}
}
return v;
}
triple[][] gBlur(triple[][] pm){
int n=pm.length;
int m=gFilt.length;
int di=floor((real)m/2);
triple[][]pmb=new triple[n][n];
triple t,s;
pen[][] v=new pen[n][n];
for(int i=0; i < n; ++i){
for(int j=0; j < n; ++j){
s=(0,0,0);
for(int gi=-di; gi <= di; ++gi){
for(int gj=-di; gj <=di; ++gj){
s+=pm[(n+i+gi)%n][(n+j+gj)%n]*gFilt[gi+di][gj+di];
}
}
pmb[i][j]=s;
}
}
return pmb;
}
image(matrix2pen(pm),(0,0),(1,1));
image(matrix2pen(gBlur(pm)),(1,0),(2,1));
image(matrix2pen(gBlur(gBlur(pm))),(2,0),(3,1));
It uses a sample color matrix in pm.asy
below:
triple[][] pm={
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,205,156),(255,205,156),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,248,240),(255,135,29),(255,135,29),(255,248,240),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,250),(255,255,255),(255,196,137),(255,120,0),(255,120,0),(255,196,137),(255,255,255),(255,253,250),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,232,211),(255,131,17),(255,126,1),(255,126,1),(255,131,17),(255,232,211),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,172,101),(255,117,0),(255,130,3),(255,130,3),(255,117,0),(255,172,101),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,251),(255,255,255),(255,213,172),(255,122,5),(255,128,3),(255,127,0),(255,127,0),(255,128,3),(255,122,5),(255,213,172),(255,255,255),(255,253,251),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,254),(255,254,253),(255,255,255),(255,152,57),(255,120,0),(255,129,3),(255,127,0),(255,127,0),(255,129,3),(255,120,0),(255,152,57),(255,255,255),(255,254,253),(255,255,254),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,253,252),(255,255,255),(255,201,145),(255,121,0),(255,128,4),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,4),(255,121,0),(255,201,145),(255,255,255),(255,253,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,253),(255,255,255),(255,239,224),(255,135,32),(255,122,0),(255,129,2),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,2),(255,122,0),(255,135,32),(255,239,224),(255,255,255),(255,254,253),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,189,130),(255,117,0),(255,130,5),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,130,5),(255,117,0),(255,189,130),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,230,207),(255,130,23),(255,126,0),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,126,0),(255,130,23),(255,230,207),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,255,255),(255,254,252),(255,255,255),(255,165,80),(255,117,0),(255,130,3),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,130,3),(255,117,0),(255,165,80),(255,255,255),(255,254,252),(255,255,255),(255,255,255),(255,255,255),},
{(255,255,255),(255,255,255),(255,253,251),(255,255,255),(255,219,182),(255,126,11),(255,127,1),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,127,1),(255,126,11),(255,219,182),(255,255,255),(255,253,251),(255,255,255),(255,255,255),},
{(255,255,255),(255,254,254),(255,255,255),(255,246,237),(255,147,54),(255,120,0),(255,129,3),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,3),(255,120,0),(255,147,54),(255,246,237),(255,255,255),(255,254,254),(255,255,255),},
{(255,255,255),(255,254,252),(255,255,255),(255,201,151),(255,118,0),(255,129,4),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,129,4),(255,118,0),(255,201,151),(255,255,255),(255,254,252),(255,255,255),},
{(255,254,254),(255,255,255),(255,239,223),(255,130,17),(255,125,0),(255,128,1),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,127,0),(255,128,1),(255,125,0),(255,130,17),(255,239,223),(255,255,255),(255,254,254),},
{(255,252,250),(255,255,255),(255,182,109),(255,120,0),(255,131,7),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,129,3),(255,131,7),(255,120,0),(255,182,109),(255,255,255),(255,252,250),},
{(255,255,255),(255,219,184),(255,119,7),(255,118,0),(255,120,1),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,119,0),(255,120,1),(255,118,0),(255,119,7),(255,219,184),(255,255,255),},
{(255,255,255),(255,225,195),(255,197,142),(255,204,157),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,203,154),(255,204,157),(255,197,142),(255,225,195),(255,255,255),},
{(252,252,253),(252,253,254),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,255,255),(252,253,254),(252,252,253),},
{(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),(255,255,255),},
{(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),(190,190,207),},
{(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),(0,0,54),},
{(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),(3,3,66),},
};
To get a standalone gblur.eps
just run asy gblur.asy
,
to get gblur.pdf
run asy -f pdf gblur.asy
.
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}
Best Answer
You can start from