Exemplo n.º 1
0
def goRangeFunctions():
    xmin, xmax, sigma = -3.5, 3.5, 1.0
    nx = 351
    dx = (xmax - xmin) / (nx - 1)
    fx = xmin
    sx = Sampling(nx, dx, fx)
    yg = BilateralFilter.sampleRangeFunction(gauss, sigma, sx)
    yt = BilateralFilter.sampleRangeFunction(tukey, sigma, sx)
    #yh = BilateralFilter.sampleRangeFunction(huber,sigma,sx)
    #x = rampfloat(fx,dx,nx)
    #yg = mul(x,yg)
    #yh = mul(x,yh)
    #yt = mul(x,yt)
    sp = SimplePlot()
    sp.setBackground(backgroundColor)
    sp.setFontSizeForSlide(1.0, 0.9)
    sp.setSize(700, 500)
    sp.setHLabel(" ")
    sp.setVLabel(" ")
    solid = PointsView.Line.SOLID
    dash = PointsView.Line.DASH
    dot = PointsView.Line.DOT
    #pv = sp.addPoints(sx,yh); pv.setLineStyle(dot); pv.setLineWidth(4)
    pv = sp.addPoints(sx, yg)
    pv.setLineStyle(dash)
    pv.setLineWidth(4)
    pv = sp.addPoints(sx, yt)
    pv.setLineStyle(solid)
    pv.setLineWidth(4)
    if pngDir:
        sp.paintToPng(720, 3.3, pngDir + "blftg.png")
Exemplo n.º 2
0
Arquivo: vg.py Projeto: zfbi/lss
def goBilateral(f):
    g = like(f)
    sigmaS = 24.0  # spatial filter sigma
    sigmaR = computeSigmaR(f)
    blf = BilateralFilter(sigmaS, sigmaR)
    blf.apply(f, g)
    plot(g, cmin=-1, cmax=1, name='bilateral filter')
Exemplo n.º 3
0
def goBilateral(f):
  g = like(f)
  sigmaS = 24.0 # spatial filter sigma
  sigmaR = computeSigmaR(f)
  blf = BilateralFilter(sigmaS,sigmaR)
  blf.apply(f,g)
  plot(g,cmin=-1,cmax=1,name='bilateral filter')
Exemplo n.º 4
0
def goRangeFunctions():
  xmin,xmax,sigma = -3.5,3.5,1.0
  nx = 351
  dx = (xmax-xmin)/(nx-1)
  fx = xmin
  sx = Sampling(nx,dx,fx)
  yg = BilateralFilter.sampleRangeFunction(gauss,sigma,sx)
  yt = BilateralFilter.sampleRangeFunction(tukey,sigma,sx)
  #yh = BilateralFilter.sampleRangeFunction(huber,sigma,sx)
  #x = rampfloat(fx,dx,nx)
  #yg = mul(x,yg)
  #yh = mul(x,yh)
  #yt = mul(x,yt)
  sp = SimplePlot()
  sp.setBackground(backgroundColor)
  sp.setFontSizeForSlide(1.0,0.9)
  sp.setSize(700,500)
  sp.setHLabel(" ")
  sp.setVLabel(" ")
  solid = PointsView.Line.SOLID
  dash = PointsView.Line.DASH
  dot = PointsView.Line.DOT
  #pv = sp.addPoints(sx,yh); pv.setLineStyle(dot); pv.setLineWidth(4)
  pv = sp.addPoints(sx,yg); pv.setLineStyle(dash); pv.setLineWidth(4)
  pv = sp.addPoints(sx,yt); pv.setLineStyle(solid); pv.setLineWidth(4)
  if pngDir:
    sp.paintToPng(720,3.3,pngDir+"blftg.png")
Exemplo n.º 5
0
def bilateralFilterQC(sigmaS, sigmaX, t, x):
    y = like(x)
    bf = BilateralFilter(sigmaS, sigmaX)
    if t:
        qc = bf.applyQC(t, x, y)
    else:
        qc = bf.applyQC(x, y)
    return qc.sx, qc.sn, qc.sd, qc.tn, qc.td
Exemplo n.º 6
0
def bilateralFilterQC(sigmaS,sigmaX,t,x):
  y = like(x)
  bf = BilateralFilter(sigmaS,sigmaX)
  if t:
    qc = bf.applyQC(t,x,y)
  else:
    qc = bf.applyQC(x,y)
  return qc.sx,qc.sn,qc.sd,qc.tn,qc.td
Exemplo n.º 7
0
def bilateralFilter(sigmaS,sigmaX,t,x):
  y = like(x)
  bf = BilateralFilter(sigmaS,sigmaX)
  if t:
    bf.apply(t,x,y)
  else:
    bf.apply(x,y)
  return y
Exemplo n.º 8
0
def goFilterImpulses():
  xa,s1,s2,clip = getImage()
  xb = makeImpulses(12,len(xa[0]),len(xa))
  t = diffusionTensors(2.0,xa)
  plot(xa,s1,s2,1.3)
  #plot(xb,s1,s2,0.9)
  for sigmaR in [0.1,1.0,100.0]:
  #for sigmaR in [100.0]:
    y = like(xa)
    bf = BilateralFilter(30.0,sigmaR)
    bf.setType(BilateralFilter.Type.TUKEY)
    bf.applyAB(t,xa,xb,y)
    y = smoothS(y)
    #plot(y,s1,s2,0.5*max(y))
    plot(y,s1,s2,0.1)
Exemplo n.º 9
0
def goRandomBlocks():
  n1 = 801
  x = makeBlocks(n1)
  plotB(x,x,-12,12,"rbx")
  return
  y = add(x,makeNoiseForBlocks(3141,8.0,3.0,n1))
  plotB(x,y,-12,12,"rbxy")
  sigmaS = 20.0
  yqqd = qqd(y)
  z = zerofloat(n1)
  for scale in [0.01,0.5,1.0,1.5,10,100.0]:
    sigmaX = scale*yqqd
    print "sigmaS =",sigmaS," sigmaX =",sigmaX
    bf = BilateralFilter(sigmaS,sigmaX)
    bf.setType(BilateralFilter.Type.TUKEY)
    bf.apply(y,z)
    png = "rbxz"+str(int(scale*10+0.5))
    if len(png)==1: png = "0"+png
    plotB(x,z,-12,12,png=png)
Exemplo n.º 10
0
def goApproximation():
    factor = 0.67448  # 3rd quartile of standard normal distribution (sigma = 1)
    sigma = 1.401114
    pmin, pmax = -9.0, 9.0
    np, dp, fp = 301, 0.06, pmin
    nk, dk, fk = 13, 1.5, pmin
    sp = Sampling(np, dp, fp)
    sk = Sampling(nk, dk, fk)
    type = BilateralFilter.Type.GAUSS
    rf = BilateralFilter.sampleRangeFunction(type, sigma, sp)
    rg = BilateralFilter.sampleRangeFunction(type, sigma / sqrt(2.0), sp)
    method = CubicInterpolator.Method.MONOTONIC
    rfi = CubicInterpolator(method, np, rampfloat(fp, dp, np), rf)
    rgi = CubicInterpolator(method, np, rampfloat(fp, dp, np), rg)
    rr = zerofloat(np, np)
    ra = zerofloat(np, np)
    r0 = zerofloat(np, np)
    rh = zerofloat(np, np)
    for i in range(np):
        pi = sp.getValue(i)
        for j in range(np):
            pj = sp.getValue(j)
            rr[i][j] = rfi.interpolate(pi - pj)
            for k in range(nk):
                pk = sk.getValue(k)
                rjk = rgi.interpolate(pj - pk)
                rik = rgi.interpolate(pi - pk)
                #hik = hat(dk,pi-pk)
                #ra[i][j] += hik*rjk
                ra[i][j] += rik * rjk
                if k == nk / 2:
                    r0[i][j] = rjk
                    rh[i][j] = rik * rjk
                    #rh[i][j] = hik*rjk
    rr = div(rr, max(rr))
    r0 = div(r0, max(r0))
    rh = div(rh, max(rh))
    ra = div(ra, max(ra))
    plotR2(sp, rr, "blfrr")
    plotR2(sp, r0, "blfr0")
    plotR2(sp, rh, "blfrh")
    plotR2(sp, ra, "blfra")
Exemplo n.º 11
0
def goApproximation():
  factor = 0.67448 # 3rd quartile of standard normal distribution (sigma = 1)
  sigma = 1.401114
  pmin,pmax = -9.0,9.0
  np,dp,fp = 301,0.06,pmin
  nk,dk,fk =  13,1.5,pmin
  sp = Sampling(np,dp,fp)
  sk = Sampling(nk,dk,fk)
  type = BilateralFilter.Type.GAUSS
  rf = BilateralFilter.sampleRangeFunction(type,sigma,sp)
  rg = BilateralFilter.sampleRangeFunction(type,sigma/sqrt(2.0),sp)
  method = CubicInterpolator.Method.MONOTONIC
  rfi = CubicInterpolator(method,np,rampfloat(fp,dp,np),rf)
  rgi = CubicInterpolator(method,np,rampfloat(fp,dp,np),rg)
  rr = zerofloat(np,np)
  ra = zerofloat(np,np)
  r0 = zerofloat(np,np)
  rh = zerofloat(np,np)
  for i in range(np):
    pi = sp.getValue(i)
    for j in range(np):
      pj = sp.getValue(j)
      rr[i][j] = rfi.interpolate(pi-pj)
      for k in range(nk):
        pk = sk.getValue(k)
        rjk = rgi.interpolate(pj-pk)
        rik = rgi.interpolate(pi-pk)
        #hik = hat(dk,pi-pk)
        #ra[i][j] += hik*rjk
        ra[i][j] += rik*rjk
        if k==nk/2:
          r0[i][j] = rjk
          rh[i][j] = rik*rjk
          #rh[i][j] = hik*rjk
  rr = div(rr,max(rr))
  r0 = div(r0,max(r0))
  rh = div(rh,max(rh))
  ra = div(ra,max(ra))
  plotR2(sp,rr,"blfrr")
  plotR2(sp,r0,"blfr0")
  plotR2(sp,rh,"blfrh")
  plotR2(sp,ra,"blfra")
Exemplo n.º 12
0
def bilateralFilter(sigmaS, sigmaX, t, x):
    y = like(x)
    bf = BilateralFilter(sigmaS, sigmaX)
    if t:
        bf.apply(t, x, y)
    else:
        bf.apply(x, y)
    return y
Exemplo n.º 13
0
 def goOnce(v1,v2):
   t11,t12,t22 = like(g11),like(g12),like(g22)
   v = getAnglesFromGradients(v1,v2)
   sigmaS = 24.0 # spatial filter sigma
   sigmaR = computeSigmaR(v1)
   blf = BilateralFilter(sigmaS,sigmaR)
   blf.setType(BilateralFilter.Type.TUKEY_ANGLE)
   blf.applyABC(g,v,g11,t11)
   blf.applyABC(g,v,g12,t12)
   blf.applyABC(g,v,g22,t22)
   u1,u2,_,_,_,_ = getEigenFromTensors(t11,t12,t22)
   return u1,u2
Exemplo n.º 14
0
def goFilterRandom():
    xa, s1, s2, clip = getImage()
    plot(xa, s1, s2, clip)
    n1, n2 = len(xa[0]), len(xa)
    xb = makeRandom(n1, n2)
    t = diffusionTensors(2.0, xa)
    #plot(xa,s1,s2,1.3)
    #plot(xb,s1,s2,0.5)
    xqqd = qqd(x)
    for sigmaR in [xqqd, 100 * xqqd]:
        y = like(xa)
        bf = BilateralFilter(30.0, sigmaR)
        bf.setType(BilateralFilter.Type.TUKEY)
        bf.applyAB(t, xa, xb, y)
        plot(y, s1, s2, 0.1)
        bf.apply(t, xa, y)
        plot(y, s1, s2, clip)
Exemplo n.º 15
0
def goFilterRandom():
  xa,s1,s2,clip = getImage()
  plot(xa,s1,s2,clip)
  n1,n2 = len(xa[0]),len(xa)
  xb = makeRandom(n1,n2)
  t = diffusionTensors(2.0,xa)
  #plot(xa,s1,s2,1.3)
  #plot(xb,s1,s2,0.5)
  xqqd = qqd(x)
  for sigmaR in [xqqd,100*xqqd]:
    y = like(xa)
    bf = BilateralFilter(30.0,sigmaR)
    bf.setType(BilateralFilter.Type.TUKEY)
    bf.applyAB(t,xa,xb,y)
    plot(y,s1,s2,0.1)
    bf.apply(t,xa,y)
    plot(y,s1,s2,clip)
Exemplo n.º 16
0
def goFilterImpulses():
    xa, s1, s2, clip = getImage()
    xb = makeImpulses(12, len(xa[0]), len(xa))
    t = diffusionTensors(2.0, xa)
    plot(xa, s1, s2, 1.3)
    #plot(xb,s1,s2,0.9)
    for sigmaR in [0.1, 1.0, 100.0]:
        #for sigmaR in [100.0]:
        y = like(xa)
        bf = BilateralFilter(30.0, sigmaR)
        bf.setType(BilateralFilter.Type.TUKEY)
        bf.applyAB(t, xa, xb, y)
        y = smoothS(y)
        #plot(y,s1,s2,0.5*max(y))
        plot(y, s1, s2, 0.1)
Exemplo n.º 17
0
def goRandomBlocks():
    n1 = 801
    x = makeBlocks(n1)
    plotB(x, x, -12, 12, "rbx")
    return
    y = add(x, makeNoiseForBlocks(3141, 8.0, 3.0, n1))
    plotB(x, y, -12, 12, "rbxy")
    sigmaS = 20.0
    yqqd = qqd(y)
    z = zerofloat(n1)
    for scale in [0.01, 0.5, 1.0, 1.5, 10, 100.0]:
        sigmaX = scale * yqqd
        print "sigmaS =", sigmaS, " sigmaX =", sigmaX
        bf = BilateralFilter(sigmaS, sigmaX)
        bf.setType(BilateralFilter.Type.TUKEY)
        bf.apply(y, z)
        png = "rbxz" + str(int(scale * 10 + 0.5))
        if len(png) == 1: png = "0" + png
        plotB(x, z, -12, 12, png=png)