2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-19 11:38:05 +02:00

Add linear convolution example

This commit is contained in:
Martin Thoma 2016-11-20 11:05:29 +01:00
parent 0d9ba773c4
commit fec222d59c
4 changed files with 122 additions and 0 deletions

View file

@ -0,0 +1,31 @@
SOURCE = convolution-linear
DELAY = 80
DENSITY = 300
WIDTH = 512
make:
pdflatex $(SOURCE).tex -output-format=pdf
make clean
clean:
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
gif:
pdfcrop $(SOURCE).pdf
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
make clean
png:
make
make svg
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
transparentGif:
convert $(SOURCE).pdf -transparent white result.gif
make clean
svg:
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
pdf2svg $(SOURCE).pdf $(SOURCE).svg
# Necessary, as pdf2svg does not always create valid svgs:
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg

View file

@ -0,0 +1,3 @@
Compiled example
----------------
![Example](convolution-linear.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,88 @@
\documentclass{standalone}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\newcommand{\filtersize}{3}
\newcommand{\filterx}{8}
\newcommand{\filtery}{2.2}
\newcommand{\filteroffset}{1}
\newcommand{\imagesize}{7}
\newcommand{\imagex}{0}
\newcommand{\imagey}{0}
\newcommand{\imageoffset}{2}
\newcommand{\outx}{13}
\newcommand{\outy}{0}
\newcommand{\outoffset}{2}
\newcommand{\percx}{1}
\newcommand{\percy}{2}
\begin{tikzpicture}
% ,circle,thick,draw=black,fill=black,minimum width=4pt,minimum height=4pt
\tikzstyle{point}=[draw=none,inner sep=0pt]
% draw perceptive field
\node (p1)[point] at (\imagex+\percx,
\imagey+\percy+\percx*\imageoffset/\imagesize) {};
\node (p2)[point] at (\imagex+\percx+\filtersize,
\imagey+\percy+\percx*\imageoffset/\imagesize+\filtersize*\imageoffset/\imagesize) {};
\node (p3)[point,blue] at (\imagex+\percx+\filtersize,
\imagey+\percy+\filtersize+\percx*\imageoffset/\imagesize+\filtersize*\imageoffset/\imagesize) {};
\node (p4)[point] at (\imagex+\percx,
\imagey+\percy+\filtersize+\percx*\imageoffset/\imagesize) {};
\draw[fill=gray] (p1.center) -- (p2.center) -- (p3.center) -- (p4.center) -- (p1.center);
% draw output point
\node (o1)[point] at (\outx+\percx+1,
\outy+\percy+\percx*\outoffset/\imagesize+1+1*\outoffset/\imagesize) {};
\node (o2)[point] at (\outx+\percx+2,
\outy+\percy+\percx*\outoffset/\imagesize+1*\outoffset/\imagesize+1+1*\outoffset/\imagesize) {};
\node (o3)[point,blue] at (\outx+\percx+2,
\outy+\percy+1+\percx*\outoffset/\imagesize+1*\outoffset/\imagesize+1+1*\outoffset/\imagesize) {};
\node (o4)[point] at (\outx+\percx+1,
\outy+\percy+2+\percx*\outoffset/\imagesize+1*\outoffset/\imagesize) {};
\draw[fill=black] (o1.center) -- (o2.center) -- (o3.center) -- (o4.center) -- (o1.center);
% draw image
\foreach \x in {0,...,\imagesize}
{
\draw (\imagex+\x, \imagey+\x*\imageoffset/\imagesize) -- (\imagex+\x, \imagey+\imagesize+\x*\imageoffset/\imagesize);
\draw (\imagex, \imagey+\x) -- (\imagex+\imagesize, \imagey+\x+\imageoffset);
}
% draw filter
\foreach \x in {0,...,\filtersize}
{
\draw (\filterx+\x, \filtery+\x*\filteroffset/\filtersize) -- (\filterx+\x, \filtery+\filtersize+\x*\filteroffset/\filtersize);
\draw (\filterx, \filtery+\x) -- (\filterx+\filtersize, \filtery+\x+\filteroffset);
}
% draw out
\foreach \x in {0,...,\imagesize}
{
\draw (\outx+\x, \outy+\x*\outoffset/\imagesize) -- (\outx+\x, \outy+\imagesize+\x*\outoffset/\imagesize);
\draw (\outx, \outy+\x) -- (\outx+\imagesize, \outy+\x+\outoffset);
}
\node at (\imagex + \imagesize/2,\imagey + \imagesize + 2) {$I \in \mathbb{R}^{\imagesize \times \imagesize}$};
\node at (\filterx + \filtersize/2,\filtery + \filtersize + 2) {$F \in \mathbb{R}^{\filtersize \times \filtersize}$};
\node at (\outx + \imagesize/2,\outy + \imagesize + 2) {$I' \in \mathbb{R}^{\imagesize \times \imagesize}$};
\node[draw,circle] (sumsymb) at (\filterx + \filtersize+1,\filtery + \filtersize/2 + \filteroffset-0.5) {$\sum$};
\draw[dashed] (1.5, 2.9) -- (10.5, 2.9) -- (sumsymb.center);
\draw[dashed] (1.5, 2.9+\filtersize-1) -- (10.5, 2.9+\filtersize-1) -- (sumsymb.center);
\draw[dashed] (1.5+\filtersize-1, 2.9+\filtersize-1+2*\filteroffset/3) -- (10.5+\filtersize-1, 2.9+\filtersize-1+2*\filteroffset/3) -- (sumsymb.center);
\draw[dashed] (1.5+\filtersize-1, 2.9+2*\filteroffset/3) -- (10.5+\filtersize-1, 2.9+2*\filteroffset/3) -- (sumsymb.center);
\draw[dashed] (sumsymb.center) -- (15, 4);
\node[draw,circle,fill=white] at (5.5, 2.9) {$+$};
\node[draw,circle,fill=white] at (5.5+\filtersize-1, 2.9+2*\filteroffset/3) {$+$};
\node[draw,circle,fill=white] at (5.5+\filtersize-1, 2.9+2*\filteroffset/3+\filtersize-1) {$+$};
\node[draw,circle,fill=white] at (5.5, 2.9+\filtersize-1) {$+$};
\node[draw,circle,fill=white] at (sumsymb.center) {$\sum$};
\end{tikzpicture}
\end{document}