Ejemplo n.º 1
0
def af_gauss_sigmas(data,sigmas):
  d_kernels = []
  for s in sigmas:
    af_gaussian2D(s)
    d_kernels.append(d_k)
  
  out = []
  for d in data:
    d_img = af.np_to_af_array(d)

    for d_k in d_kernels:
      #res = af.convolve2_separable(d_k, af.transpose(d_k), d_img)
      res = af.convolve2(d_img, d_k)
      # create numpy array
      out.append(res.__array__())
  return out
Ejemplo n.º 2
0
 def constrainPupil(self, pupil, pupil_mask=None, flag_smooth_phase=True):
     #makes sure pupil amplitude is between 0 and 1.
     #if pupil mask is passed in, amplitude will become the mask
     pupil_abs = np.abs(pupil)
     pupil_phase = af.shift(af.arg(pupil), pupil.shape[0] // 2,
                            pupil.shape[1] // 2)
     #smoothen phase
     pupil_phase = af.convolve2(pupil_phase, self.gaussian_kernel)
     if pupil_mask is None:
         pupil_abs[pupil_abs > 1.0] = 1.0
         pupil_abs[pupil_abs < 0] = 0.0
     else:
         pupil_abs[:] = np.abs(pupil_mask)
     pupil = pupil_abs * np.exp(
         1.0j * af.shift(pupil_phase, -1 * int(pupil.shape[0] // 2),
                         -1 * int(pupil.shape[1] // 2)))
     return pupil
Ejemplo n.º 3
0
def af_gauss(data,kernels):
  d_kernels = []
  for k in kernels:
    d_k = af.np_to_af_array(k)
    d_kernels.append(af.matmul(d_k,af.transpose(d_k)))
  
  ##d_k = af.matmul(af.transpose(d_k),d_k)
  out = []
  for d in data:
    d_img = af.np_to_af_array(d)

    for d_k in d_kernels:
      #res = af.convolve2_separable(d_k, af.transpose(d_k), d_img)
      res = af.convolve2(d_img, d_k)
      # create numpy array
      out.append(res.__array__())
  return out
Ejemplo n.º 4
0
af.display(af.fft3(a))
af.display(af.dft(a))
af.display(af.real(af.ifft3(af.fft3(a))))
af.display(af.real(af.idft(af.dft(a))))

a = af.randu(10, 1)
b = af.randu(3, 1)
af.display(af.convolve1(a, b))
af.display(af.fft_convolve1(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))

a = af.randu(5, 5)
b = af.randu(3, 3)
af.display(af.convolve2(a, b))
af.display(af.fft_convolve2(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))

a = af.randu(5, 5, 3)
b = af.randu(3, 3, 2)
af.display(af.convolve3(a, b))
af.display(af.fft_convolve3(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))

b = af.randu(3, 1)
x = af.randu(10, 1)
a = af.randu(2, 1)
af.display(af.fir(b, x))
Ejemplo n.º 5
0
  if not args.raw:
    print "--- Starting measurements ---"

  for i in range(args.N):
    ## arrayfire measurement
    start = time.clock()
    #---
    afimg = af.np_to_af_array(img)
    af.sync()
    #---
    end = time.clock()
    af_cpy_hd[i] = end-start

    start = time.clock()
    #---
    afres = af.convolve2(afimg, afsmk)
    af.sync()
    #---
    end = time.clock()
    af_convolve[i] = end-start

    start = time.clock()
    #---
    afres_h = afres.__array__()
    af.sync()
    #---
    end = time.clock()
    af_cpy_dh[i] = end-start

    ksize = int(3*args.sigma)*2+1
    convopts = vigra.blockwise.convolutionOptions((ksize,ksize),sigma=args.sigma,numThreads=8)
Ejemplo n.º 6
0
def simple_signal(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)

    a = af.randu(10, 1)
    pos0 = af.randu(10) * 10
    display_func(af.approx1(a, pos0))

    a = af.randu(3, 3)
    pos0 = af.randu(3, 3) * 10
    pos1 = af.randu(3, 3) * 10

    display_func(af.approx2(a, pos0, pos1))

    a = af.randu(8, 1)
    display_func(a)

    display_func(af.fft(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft(af.fft(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(4, 4)
    display_func(a)

    display_func(af.fft2(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft2(af.fft2(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(4, 4, 2)
    display_func(a)

    display_func(af.fft3(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft3(af.fft3(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(10, 1)
    b = af.randu(3, 1)
    display_func(af.convolve1(a, b))
    display_func(af.fft_convolve1(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5)
    b = af.randu(3, 3)
    display_func(af.convolve2(a, b))
    display_func(af.fft_convolve2(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5, 3)
    b = af.randu(3, 3, 2)
    display_func(af.convolve3(a, b))
    display_func(af.fft_convolve3(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))


    b = af.randu(3, 1)
    x = af.randu(10, 1)
    a = af.randu(2, 1)
    display_func(af.fir(b, x))
    display_func(af.iir(b, a, x))
Ejemplo n.º 7
0
import sys
from array import array

def af_assert(left, right, eps=1E-6):
    if (af.max(af.abs(left -right)) > eps):
        raise ValueError("Arrays not within dictated precision")
    return

if __name__ == "__main__":
    if (len(sys.argv) > 1):
        af.set_device(int(sys.argv[1]))
    af.info()

    h_dx = array('f', (1.0/12, -8.0/12, 0, 8.0/12, 1.0/12))
    h_spread = array('f', (1.0/5, 1.0/5, 1.0/5, 1.0/5, 1.0/5))

    img = af.randu(640, 480)
    dx = af.Array(h_dx, (5,1))
    spread = af.Array(h_spread, (1, 5))
    kernel = af.matmul(dx, spread)

    full_res = af.convolve2(img, kernel)
    sep_res = af.convolve2_separable(dx, spread, img)

    af_assert(full_res, sep_res)

    print("full      2D convolution time: %.5f ms" %
          (1000 * af.timeit(af.convolve2, img, kernel)))
    print("separable 2D convolution time: %.5f ms" %
          (1000 * af.timeit(af.convolve2_separable, dx, spread, img)))
Ejemplo n.º 8
0
def simple_signal(verbose=False):
    display_func = _util.display_func(verbose)
    print_func = _util.print_func(verbose)

    a = af.randu(10, 1)
    pos0 = af.randu(10) * 10
    display_func(af.approx1(a, pos0))

    a = af.randu(3, 3)
    pos0 = af.randu(3, 3) * 10
    pos1 = af.randu(3, 3) * 10

    display_func(af.approx2(a, pos0, pos1))

    a = af.randu(8, 1)
    display_func(a)

    display_func(af.fft(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft(af.fft(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(4, 4)
    display_func(a)

    display_func(af.fft2(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft2(af.fft2(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(4, 4, 2)
    display_func(a)

    display_func(af.fft3(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft3(af.fft3(a))))
    display_func(af.real(af.idft(af.dft(a))))

    a = af.randu(10, 1)
    b = af.randu(3, 1)
    display_func(af.convolve1(a, b))
    display_func(af.fft_convolve1(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5)
    b = af.randu(3, 3)
    display_func(af.convolve2(a, b))
    display_func(af.fft_convolve2(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5, 3)
    b = af.randu(3, 3, 2)
    display_func(af.convolve3(a, b))
    display_func(af.fft_convolve3(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    b = af.randu(3, 1)
    x = af.randu(10, 1)
    a = af.randu(2, 1)
    display_func(af.fir(b, x))
    display_func(af.iir(b, a, x))
Ejemplo n.º 9
0

def af_assert(left, right, eps=1E-6):
    if (af.max(af.abs(left - right)) > eps):
        raise ValueError("Arrays not within dictated precision")
    return


if __name__ == "__main__":
    if (len(sys.argv) > 1):
        af.set_device(int(sys.argv[1]))
    af.info()

    h_dx = array('f', (1.0 / 12, -8.0 / 12, 0, 8.0 / 12, 1.0 / 12))
    h_spread = array('f', (1.0 / 5, 1.0 / 5, 1.0 / 5, 1.0 / 5, 1.0 / 5))

    img = af.randu(3072, 3072)
    dx = af.Array(h_dx, (5, 1))
    spread = af.Array(h_spread, (1, 5))
    kernel = af.matmul(dx, spread)

    full_res = af.convolve2(img, kernel)
    sep_res = af.convolve2_separable(dx, spread, img)

    af_assert(full_res, sep_res)

    print("full      2D convolution time: %.5f ms" %
          (1000 * af.timeit(af.convolve2, img, kernel)))
    print("separable 2D convolution time: %.5f ms" %
          (1000 * af.timeit(af.convolve2_separable, dx, spread, img)))
af.display(af.fft3(a))
af.display(af.dft(a))
af.display(af.real(af.ifft3(af.fft3(a))))
af.display(af.real(af.idft(af.dft(a))))

a = af.randu(10, 1)
b = af.randu(3, 1)
af.display(af.convolve1(a, b))
af.display(af.fft_convolve1(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))

a = af.randu(5, 5)
b = af.randu(3, 3)
af.display(af.convolve2(a, b))
af.display(af.fft_convolve2(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))

a = af.randu(5, 5, 3)
b = af.randu(3, 3, 2)
af.display(af.convolve3(a, b))
af.display(af.fft_convolve3(a, b))
af.display(af.convolve(a, b))
af.display(af.fft_convolve(a, b))


b = af.randu(3, 1)
x = af.randu(10, 1)
a = af.randu(2, 1)
Ejemplo n.º 11
0
def simple_signal(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)

    signal = af.randu(10)
    x_new  = af.randu(10)
    x_orig = af.randu(10)
    display_func(af.approx1(signal, x_new, xp = x_orig))

    signal = af.randu(3, 3)
    x_new  = af.randu(3, 3)
    x_orig = af.randu(3, 3)
    y_new  = af.randu(3, 3)
    y_orig = af.randu(3, 3)

    display_func(af.approx2(signal, x_new, y_new, xp = x_orig, yp = y_orig))

    a = af.randu(8, 1)
    display_func(a)

    display_func(af.fft(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft(af.fft(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft(a)
    af.ifft_inplace(b)
    display_func(b)
    af.fft_inplace(b)
    display_func(b)

    b = af.fft_r2c(a)
    c = af.fft_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(4, 4)
    display_func(a)

    display_func(af.fft2(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft2(af.fft2(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft2(a)
    af.ifft2_inplace(b)
    display_func(b)
    af.fft2_inplace(b)
    display_func(b)

    b = af.fft2_r2c(a)
    c = af.fft2_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(4, 4, 2)
    display_func(a)

    display_func(af.fft3(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft3(af.fft3(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft3(a)
    af.ifft3_inplace(b)
    display_func(b)
    af.fft3_inplace(b)
    display_func(b)

    b = af.fft3_r2c(a)
    c = af.fft3_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(10, 1)
    b = af.randu(3, 1)
    display_func(af.convolve1(a, b))
    display_func(af.fft_convolve1(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5)
    b = af.randu(3, 3)
    display_func(af.convolve2(a, b))
    display_func(af.fft_convolve2(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5, 3)
    b = af.randu(3, 3, 2)
    display_func(af.convolve3(a, b))
    display_func(af.fft_convolve3(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))


    b = af.randu(3, 1)
    x = af.randu(10, 1)
    a = af.randu(2, 1)
    display_func(af.fir(b, x))
    display_func(af.iir(b, a, x))

    display_func(af.medfilt1(a))
    display_func(af.medfilt2(a))
    display_func(af.medfilt(a))
Ejemplo n.º 12
0
def simple_signal(verbose=False):
    display_func = _util.display_func(verbose)

    signal = af.randu(10)
    x_new = af.randu(10)
    x_orig = af.randu(10)
    display_func(af.approx1(signal, x_new, xp=x_orig))

    signal = af.randu(3, 3)
    x_new = af.randu(3, 3)
    x_orig = af.randu(3, 3)
    y_new = af.randu(3, 3)
    y_orig = af.randu(3, 3)

    display_func(af.approx2(signal, x_new, y_new, xp=x_orig, yp=y_orig))

    a = af.randu(8, 1)
    display_func(a)

    display_func(af.fft(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft(af.fft(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft(a)
    af.ifft_inplace(b)
    display_func(b)
    af.fft_inplace(b)
    display_func(b)

    b = af.fft_r2c(a)
    c = af.fft_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(4, 4)
    display_func(a)

    display_func(af.fft2(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft2(af.fft2(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft2(a)
    af.ifft2_inplace(b)
    display_func(b)
    af.fft2_inplace(b)
    display_func(b)

    b = af.fft2_r2c(a)
    c = af.fft2_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(4, 4, 2)
    display_func(a)

    display_func(af.fft3(a))
    display_func(af.dft(a))
    display_func(af.real(af.ifft3(af.fft3(a))))
    display_func(af.real(af.idft(af.dft(a))))

    b = af.fft3(a)
    af.ifft3_inplace(b)
    display_func(b)
    af.fft3_inplace(b)
    display_func(b)

    b = af.fft3_r2c(a)
    c = af.fft3_c2r(b)
    display_func(b)
    display_func(c)

    a = af.randu(10, 1)
    b = af.randu(3, 1)
    display_func(af.convolve1(a, b))
    display_func(af.fft_convolve1(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    a = af.randu(5, 5)
    b = af.randu(3, 3)
    display_func(af.convolve2(a, b))
    display_func(af.fft_convolve2(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    c = af.convolve2NN(a, b)
    display_func(c)
    in_dims = c.dims()
    incoming_grad = af.constant(1, in_dims[0], in_dims[1])
    g = af.convolve2GradientNN(incoming_grad, a, b, c)
    display_func(g)

    a = af.randu(5, 5, 3)
    b = af.randu(3, 3, 2)
    display_func(af.convolve3(a, b))
    display_func(af.fft_convolve3(a, b))
    display_func(af.convolve(a, b))
    display_func(af.fft_convolve(a, b))

    b = af.randu(3, 1)
    x = af.randu(10, 1)
    a = af.randu(2, 1)
    display_func(af.fir(b, x))
    display_func(af.iir(b, a, x))

    display_func(af.medfilt1(a))
    display_func(af.medfilt2(a))
    display_func(af.medfilt(a))