kernel

from scipy import signal
import numpy as np
import torch

def create_kernel(opt):
    sigma = opt['dataset']['degradation'].get('sigma', 1.5)
    ksize = 1 + 2 * int(sigma * 3.0)

    gkern1d = signal.gaussian(ksize, std=sigma).reshape(ksize, 1)
    gkern2d = np.outer(gkern1d, gkern1d)
    gaussian_kernel = gkern2d / gkern2d.sum()
    zero_kernel = np.zeros_like(gaussian_kernel)

    kernel = np.float32([
        [gaussian_kernel, zero_kernel, zero_kernel],
        [zero_kernel, gaussian_kernel, zero_kernel],
        [zero_kernel, zero_kernel, gaussian_kernel]])

    device = torch.device(opt['device'])
    kernel = torch.from_numpy(kernel).to(device)

    return kernel
 gkern1d = signal.gaussian(ksize, std=sigma).reshape(ksize, 1)

参考:
https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.gaussian.html

scipy.signal.gaussian(M, std, sym=True)

Return a Gaussian window.

**Parameters:**	
M : int
Number of points in the output window. If zero or less, an empty array is returned.
输出窗口中的点数。 如果为零或更少,则返回一个空数组。

std : float
The standard deviation, sigma.标准差

sym : bool, optional
When True (default), generates a symmetric window, for use in filter design. When False, generates a periodic window, for use in spectral analysis.
当为 True(默认)时,生成一个对称窗口,用于滤波器设计。 当为 False 时,生成一个周期窗口,用于光谱分析。

**Returns:**	
w : ndarray

The window, with the maximum value normalized to 1 (though the value 1 does not appear if M is even and sym is True).
窗口,最大值归一化为 1(尽管如果 M 为偶数且 sym 为 True,则不会出现值 1)。
上一篇:SciPy 积分 | Python技能树征题


下一篇:数据分析系列 之python中拓展库SciPy的使用