def af_gaussianDerivative1D(s,order): radius = int(round(3*s + 0.5*order)) size = radius*2+1 csize = ct.c_int(size) csigma = ct.c_double(s) d_k = af.Array() af.safe_call(af.backend.get().af_gaussian_kernel(ct.pointer(d_k.arr),csize,1,csigma,0)) if order == 1: afx=af.range(size)-radius return -afx/s/s*d_k if order == 2: afx=((af.range(size)-radius)**2-s*s) return afx/(s**4)*d_k return d_k
def af_gauss_sigmas_sep(data,sigmas): d_kernels = [] for s in sigmas: csize = ct.c_int(int(3*s + 0.5)*2+1) csigma = ct.c_double(s) d_k = af.Array() af.safe_call(af.backend.get().af_gaussian_kernel(ct.pointer(d_k.arr),csize,1,csigma,ct.c_double(0.0))) d_kernels.append(d_k) out = [] for d in data: d_img = af.np_to_af_array(d) for d_k,i in zip(d_kernels,range(len(d_kernels))): res = af.convolve2_separable(d_k, af.transpose(d_k), d_img) # create numpy array out.append(res.__array__()) return out
def inplace_setitem(self, key, val): try: n_dims = self.numdims() if (arrayfire.util._is_number(val)): tdims = arrayfire.array._get_assign_dims(key, self.dims()) other_arr = arrayfire.array.constant_array(val, tdims[0], tdims[1], tdims[2], tdims[3], self.type()) del_other = True else: other_arr = val.arr del_other = False inds = arrayfire.array._get_indices(key) # In place assignment. Notice passing a pointer to self.arr as output arrayfire.util.safe_call(arrayfire.backend.get().af_assign_gen(ctypes.pointer(self.arr), self.arr, ctypes.c_longlong(n_dims), inds.pointer, other_arr)) if del_other: arrayfire.safe_call(arrayfire.backend.get().af_release_array(other_arr)) except RuntimeError as e: raise IndexError(str(e))
def af_gaussian2D(s): csize = ct.c_int(int(3*s)*2+1) csigma = ct.c_double(s) d_k = af.Array() af.safe_call(af.backend.get().af_gaussian_kernel(ct.pointer(d_k.arr),csize,csize,csigma,csigma)) return d_k
def get_use_count(arr): uses = ctypes.c_int(0) af.safe_call(af.backend.get().af_get_data_ref_count( af.c_pointer(uses), arr.arr)) return uses