Shortcuts

mmedit.datasets.transforms.blur_kernels

Module Contents

Functions

get_rotated_sigma_matrix(sig_x, sig_y, theta)

Calculate the rotated sigma matrix (two dimensional matrix).

_mesh_grid(kernel_size)

Generate the mesh grid, centering at zero.

calculate_gaussian_pdf(sigma_matrix, grid)

Calculate PDF of the bivariate Gaussian distribution.

bivariate_gaussian(kernel_size, sig_x[, sig_y, theta, ...])

Generate a bivariate isotropic or anisotropic Gaussian kernel.

bivariate_generalized_gaussian(kernel_size, sig_x[, ...])

Generate a bivariate generalized Gaussian kernel.

bivariate_plateau(kernel_size, sig_x, sig_y, theta, beta)

Generate a plateau-like anisotropic kernel.

random_bivariate_gaussian_kernel(kernel_size, ...[, ...])

Randomly generate bivariate isotropic or anisotropic Gaussian kernels.

random_bivariate_generalized_gaussian_kernel(...[, ...])

Randomly generate bivariate generalized Gaussian kernels.

random_bivariate_plateau_kernel(kernel_size, ...[, ...])

Randomly generate bivariate plateau kernels.

random_circular_lowpass_kernel(omega_range, kernel_size)

Generate a 2D Sinc filter.

random_mixed_kernels(kernel_list, kernel_prob, kernel_size)

Randomly generate a kernel.

mmedit.datasets.transforms.blur_kernels.get_rotated_sigma_matrix(sig_x, sig_y, theta)[源代码]

Calculate the rotated sigma matrix (two dimensional matrix).

参数
  • sig_x (float) – Standard deviation along the horizontal direction.

  • sig_y (float) – Standard deviation along the vertical direction.

  • theta (float) – Rotation in radian.

返回

Rotated sigma matrix.

返回类型

np.ndarray

mmedit.datasets.transforms.blur_kernels._mesh_grid(kernel_size)[源代码]

Generate the mesh grid, centering at zero.

参数

kernel_size (int) – The size of the kernel.

返回

x-coordinates with shape

(kernel_size, kernel_size).

y_grid (np.ndarray): y-coordinates with shape

(kernel_size, kernel_size).

xy_grid (np.ndarray): stacked coordinates with shape

(kernel_size, kernel_size, 2).

返回类型

x_grid (np.ndarray)

mmedit.datasets.transforms.blur_kernels.calculate_gaussian_pdf(sigma_matrix, grid)[源代码]

Calculate PDF of the bivariate Gaussian distribution.

参数
  • sigma_matrix (np.ndarray) – The variance matrix with shape (2, 2).

  • grid (np.ndarray) – Coordinates generated by _mesh_grid(), with shape (K, K, 2), where K is the kernel size.

返回

Un-normalized kernel.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.bivariate_gaussian(kernel_size, sig_x, sig_y=None, theta=None, grid=None, is_isotropic=True)[源代码]

Generate a bivariate isotropic or anisotropic Gaussian kernel.

In isotropic mode, only sig_x is used. sig_y and theta are ignored.

参数
  • kernel_size (int) – The size of the kernel

  • sig_x (float) – Standard deviation along horizontal direction.

  • sig_y (float | None, optional) – Standard deviation along the vertical direction. If it is None, ‘is_isotropic’ must be set to True. Default: None.

  • theta (float | None, optional) – Rotation in radian. If it is None, ‘is_isotropic’ must be set to True. Default: None.

  • grid (ndarray, optional) – Coordinates generated by _mesh_grid(), with shape (K, K, 2), where K is the kernel size. Default: None

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

normalized kernel (i.e. sum to 1).

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.bivariate_generalized_gaussian(kernel_size, sig_x, sig_y=None, theta=None, beta=1, grid=None, is_isotropic=True)[源代码]

Generate a bivariate generalized Gaussian kernel.

Described in Parameter Estimation For Multivariate Generalized Gaussian Distributions by Pascal et. al (2013). In isotropic mode, only sig_x is used. sig_y and theta is ignored.

参数
  • kernel_size (int) – The size of the kernel

  • sig_x (float) – Standard deviation along horizontal direction

  • sig_y (float | None, optional) – Standard deviation along the vertical direction. If it is None, ‘is_isotropic’ must be set to True. Default: None.

  • theta (float | None, optional) – Rotation in radian. If it is None, ‘is_isotropic’ must be set to True. Default: None.

  • beta (float, optional) – Shape parameter, beta = 1 is the normal distribution. Default: 1.

  • grid (ndarray, optional) – Coordinates generated by _mesh_grid(), with shape (K, K, 2), where K is the kernel size. Default: None

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

normalized kernel.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.bivariate_plateau(kernel_size, sig_x, sig_y, theta, beta, grid=None, is_isotropic=True)[源代码]

Generate a plateau-like anisotropic kernel.

This kernel has a form of 1 / (1+x^(beta)). Ref: https://stats.stackexchange.com/questions/203629/is-there-a-plateau-shaped-distribution # noqa In the isotropic mode, only sig_x is used. sig_y and theta is ignored.

参数
  • kernel_size (int) – The size of the kernel

  • sig_x (float) – Standard deviation along horizontal direction

  • sig_y (float) – Standard deviation along the vertical direction.

  • theta (float) – Rotation in radian.

  • beta (float) – Shape parameter, beta = 1 is the normal distribution.

  • grid (np.ndarray, optional) – Coordinates generated by _mesh_grid(), with shape (K, K, 2), where K is the kernel size. Default: None

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

normalized kernel (i.e. sum to 1).

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.random_bivariate_gaussian_kernel(kernel_size, sigma_x_range, sigma_y_range, rotation_range, noise_range=None, is_isotropic=True)[源代码]

Randomly generate bivariate isotropic or anisotropic Gaussian kernels.

In the isotropic mode, only sigma_x_range is used. sigma_y_range and rotation_range is ignored.

参数
  • kernel_size (int) – The size of the kernel.

  • sigma_x_range (tuple) – The range of the standard deviation along the horizontal direction. Default: [0.6, 5]

  • sigma_y_range (tuple) – The range of the standard deviation along the vertical direction. Default: [0.6, 5]

  • rotation_range (tuple) – Range of rotation in radian.

  • noise_range (tuple, optional) – Multiplicative kernel noise. Default: None.

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

The kernel whose parameters are sampled from the

specified range.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.random_bivariate_generalized_gaussian_kernel(kernel_size, sigma_x_range, sigma_y_range, rotation_range, beta_range, noise_range=None, is_isotropic=True)[源代码]

Randomly generate bivariate generalized Gaussian kernels.

In the isotropic mode, only sigma_x_range is used. sigma_y_range and rotation_range is ignored.

参数
  • kernel_size (int) – The size of the kernel.

  • sigma_x_range (tuple) – The range of the standard deviation along the horizontal direction. Default: [0.6, 5]

  • sigma_y_range (tuple) – The range of the standard deviation along the vertical direction. Default: [0.6, 5]

  • rotation_range (tuple) – Range of rotation in radian.

  • beta_range (float) – The range of the shape parameter, beta = 1 is the normal distribution.

  • noise_range (tuple, optional) – Multiplicative kernel noise. Default: None.

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

Normalized kernel.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.random_bivariate_plateau_kernel(kernel_size, sigma_x_range, sigma_y_range, rotation_range, beta_range, noise_range=None, is_isotropic=True)[源代码]

Randomly generate bivariate plateau kernels.

In the isotropic mode, only sigma_x_range is used. sigma_y_range and rotation_range is ignored.

参数
  • kernel_size (int) – The size of the kernel.

  • sigma_x_range (tuple) – The range of the standard deviation along the horizontal direction. Default: [0.6, 5]

  • sigma_y_range (tuple) – The range of the standard deviation along the vertical direction. Default: [0.6, 5]

  • rotation_range (tuple) – Range of rotation in radian.

  • beta_range (float) – The range of the shape parameter, beta = 1 is the normal distribution.

  • noise_range (tuple, optional) – Multiplicative kernel noise. Default: None.

  • is_isotropic (bool, optional) – Whether to use an isotropic kernel. Default: True.

返回

Plateau kernel.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.random_circular_lowpass_kernel(omega_range, kernel_size, pad_to=0)[源代码]

Generate a 2D Sinc filter.

Reference: https://dsp.stackexchange.com/questions/58301/2-d-circularly-symmetric-low-pass-filter # noqa

参数
  • omega_range (tuple) – The cutoff frequency in radian (pi is max).

  • kernel_size (int) – The size of the kernel. It must be an odd number.

  • pad_to (int, optional) – The size of the padded kernel. It must be odd or zero. Default: 0.

返回

The Sinc kernel with specified parameters.

返回类型

kernel (np.ndarray)

mmedit.datasets.transforms.blur_kernels.random_mixed_kernels(kernel_list, kernel_prob, kernel_size, sigma_x_range=[0.6, 5], sigma_y_range=[0.6, 5], rotation_range=[- np.pi, np.pi], beta_gaussian_range=[0.5, 8], beta_plateau_range=[1, 2], omega_range=[0, np.pi], noise_range=None)[源代码]

Randomly generate a kernel.

参数
  • kernel_list (list) – A list of kernel types. Choices are ‘iso’, ‘aniso’, ‘skew’, ‘generalized_iso’, ‘generalized_aniso’, ‘plateau_iso’, ‘plateau_aniso’, ‘sinc’.

  • kernel_prob (list) – The probability of choosing of the corresponding kernel.

  • kernel_size (int) – The size of the kernel.

  • sigma_x_range (list, optional) – The range of the standard deviation along the horizontal direction. Default: (0.6, 5).

  • sigma_y_range (list, optional) – The range of the standard deviation along the vertical direction. Default: (0.6, 5).

  • rotation_range (list, optional) – Range of rotation in radian. Default: (-np.pi, np.pi).

  • beta_gaussian_range (list, optional) – The range of the shape parameter for generalized Gaussian. Default: (0.5, 8).

  • beta_plateau_range (list, optional) – The range of the shape parameter for plateau kernel. Default: (1, 2).

  • omega_range (list, optional) – The range of omega used in Sinc kernel. Default: (0, np.pi).

  • noise_range (list, optional) – Multiplicative kernel noise. Default: None.

返回

The kernel whose parameters are sampled from the

specified range.

返回类型

kernel (np.ndarray)

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.