# TIKZ drawing Gaussian Blur

I am a complete newbie to latex and have been working on thesis. At the moment, I am trying to draw this and have no idea how to start. I did some google and found out that tikz is very popular for graphics. Can this be done with tikz? If so, can you point me to the right direction please, I have been working on this for the last couple days.

• It is not clear what you are asking for. You have a picture and you want to blur it in a particular way via TikZ?
– N.N.
Commented Apr 15, 2013 at 10:12
• I did a search in tikz documentation and the word "blur" has used exactly zero times! I don't think it is possible to do this in tikz and it makes sense. Blurring is a raster process while tikz is vector based graphics. However there is high probability that I'm very wrong :D Commented Apr 15, 2013 at 11:03
• I want to produce that picture in latex. The picture describes a blurring process. Commented Apr 15, 2013 at 11:03
• @wererabit Yes but do you want small squares filled with different shades or you want to give a triangle and receive this blurred shape? So what needs to be drawn in TikZ what are given by the user? Commented Apr 15, 2013 at 11:06
• The problem with that image is its small and blurry, so I want to draw the squares filled with different shades (including the white shade surrounding). Commented Apr 15, 2013 at 20:14

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

• could you let me know how can I use this in my latex? Commented Apr 16, 2013 at 11:09
• @wererabit: The simplest standard way to use it with `pdflatex`: when you got a standalone `gblur.pdf` as described, it is ready to be included as any other image with `\includegraphics[scale=1]{gblur}`. Commented Apr 16, 2013 at 12:39