def fspecialgauss2D(shape=(3,3),sigma=0.5):
"""
2D gaussian mask - should give the same result as MATLAB's
fspecial('gaussian',[shape],[sigma])
"""
m,n = [(ss-1.)/2. for ss in shape]
y,x = np.ogrid[-m:m+1,-n:n+1]
h = np.exp( -(x*x + y*y) / (2.*sigma*sigma) )
## The statement below determines the machine
## epsilon - if gaussian is smaller than that
## set to 0.
h[ h < np.finfo(h.dtype).eps*h.max() ] = 0
sumh = h.sum()
## This notation states that it takes the input
## h and then it divides by the sum and returns h
if sumh != 0:
h /= sumh
return h
评论列表
文章目录