def gaussian_kernel ( gstd ) : Nc = np . ceil ( gstd * 3 ) * 2 + 1 x = np . linspace ( - ( Nc - 1 ) / 2 , ( Nc - 1 ) / 2 , Nc , endpoint = True ) g = np . exp ( - .5 * ( ( x / gstd ) ** 2 ) ) g = g / np . sum ( g ) return g
how to make a gaussian filter kernal python
Generate odd sized truncated Gaussian
def gaussian_kernel(gstd):
    """Generate odd sized truncated Gaussian

    The generated filter kernel has a cutoff at $3\sigma$
    and is normalized to sum to 1

    Parameters
    -------------
    gstd : float
            Standard deviation of filter

    Returns
    -------------
    g : ndarray
            Array with kernel coefficients
    """
    Nc = np.ceil(gstd*3)*2+1
    x = np.linspace(-(Nc-1)/2,(Nc-1)/2,Nc,endpoint=True)
    g = np.exp(-.5*((x/gstd)**2))
    g = g/np.sum(g)

    return g