def make_2d_gaussian(self, center=(0, 0)):
'''Makes a 2D Gaussian filter with arbitary mean and variance.
Args:
center (tuple): The coordinates of the center of the Gaussian,
specified as :data:`(row, col)`. The center of the image is
:data:`(0, 0)`.
Returns:
numpy array: The Gaussian mask.
'''
sigma = self.sigma
n_rows = (self.patch_size - 1.) / 2.
n_cols = (self.patch_size - 1.) / 2.
y, x = np.ogrid[-n_rows: n_rows + 1, -n_cols: n_cols + 1]
y0, x0 = center[1], center[0]
gaussian_mask = np.exp(-((x - x0) ** 2 + (y - y0) ** 2) /
(2. * sigma ** 2))
gaussian_mask[gaussian_mask <
np.finfo(gaussian_mask.dtype).eps *
gaussian_mask.max()] = 0
gaussian_mask = 1. / gaussian_mask.max() * gaussian_mask
return gaussian_mask
评论列表
文章目录