diff options
Diffstat (limited to 'silx/image/utils.py')
-rw-r--r-- | silx/image/utils.py | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/silx/image/utils.py b/silx/image/utils.py deleted file mode 100644 index 996d010..0000000 --- a/silx/image/utils.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# /*########################################################################## -# Copyright (C) 2019 European Synchrotron Radiation Facility -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# ############################################################################*/ - -import numpy as np -from math import ceil - -def gaussian_kernel(sigma, cutoff=4, force_odd_size=False): - """ - Generates a Gaussian convolution kernel. - - :param sigma: Standard Deviation of the Gaussian curve. - :param cutoff: Parameter tuning the truncation of the Gaussian. - The higher cutoff, the biggest the array will be (and the closest to - a "true" Gaussian function). - :param force_odd_size: when set to True, the resulting array will always - have an odd size, regardless of the values of "sigma" and "cutoff". - :return: a numpy.ndarray containing the truncated Gaussian function. - The array size is 2*c*s+1 where c=cutoff, s=sigma. - - Nota: due to the quick decay of the Gaussian function, small values of the - "cutoff" parameter are usually fine. The energy difference between a - Gaussian truncated to [-c, c] and a "true" one is - erfc(c/(sqrt(2)*s)) - so choosing cutoff=4*sigma keeps the truncation error below 1e-4. - """ - size = int(ceil(2 * cutoff * sigma + 1)) - if force_odd_size and size % 2 == 0: - size += 1 - x = np.arange(size) - (size - 1.0) / 2.0 - g = np.exp(-(x / sigma) ** 2 / 2.0) - g /= g.sum() - return g |