TIKZ 绘制高斯模糊

TIKZ 绘制高斯模糊

我是 latex 的新手,一直在写论文。目前,我正在尝试绘制这个 高斯 ,但不知道如何开始。我谷歌了一下,发现 tikz 在图形方面非常流行。这可以用 tikz 完成吗?如果可以,你能给我指出正确的方向吗,我最近几天一直在研究这个问题。

答案1

在此处输入图片描述

您可以从 开始Asymptote,它包含在内,TeXLive 2012 但也可以与其他发行版一起使用。它能够处理矢量图形和光栅图形。以下示例gblur.asy文件(可以通过多种方式改进)绘制颜色矩阵,然后将高斯滤波器矩阵(来自 wiki)应用于它一次和两次:

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));

它使用下面的示例颜色矩阵pm.asy

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),},
};

要获得独立gblur.eps运行asy gblur.asy,只需gblur.pdf运行即可asy -f pdf gblur.asy

相关内容