def gaussian2DblurOperator(n,sigma):
'''
Returns a 2D Gaussan blur operator for a n x n sized domain
Constructed as a tensor product of two 1d blurs of size n
'''
x = np.linspace(0,n-1,n) # 1D domain
tau = 1.0/sigma**2 # precision
k = np.exp(-tau*x**2) # compute (un-normalized) 1D kernel
tp = scipy.linalg.special_matrices.toeplitz(k,k) # convert to an operator from n -> n
op = scipy.linalg.special_matrices.kron(tp,tp) # take the tensor product to get 2D operator
# normalize rows so density is conserved
op /= np.sum(op,axis=1)
# truncate small entries
big = np.max(op)
toosmall = 1e-4*big
op[op<toosmall] = 0
# (re) normalize rows so density is conserved
op /= np.sum(op,axis=1)
return op
评论列表
文章目录