Shortcuts

mmagic.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.

mmagic.datasets.transforms.blur_kernels.get_rotated_sigma_matrix(sig_x, sig_y, theta)[source]

Calculate the rotated sigma matrix (two dimensional matrix).

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

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

  • theta (float) – Rotation in radian.

Returns

Rotated sigma matrix.

Return type

np.ndarray

mmagic.datasets.transforms.blur_kernels._mesh_grid(kernel_size)[source]

Generate the mesh grid, centering at zero.

Parameters

kernel_size (int) – The size of the kernel.

Returns

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).

Return type

x_grid (np.ndarray)

mmagic.datasets.transforms.blur_kernels.calculate_gaussian_pdf(sigma_matrix, grid)[source]

Calculate PDF of the bivariate Gaussian distribution.

Parameters
  • 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.

Returns

Un-normalized kernel.

Return type

kernel (np.ndarray)

mmagic.datasets.transforms.blur_kernels.bivariate_gaussian(kernel_size, sig_x, sig_y=None, theta=None, grid=None, is_isotropic=True)[source]

Generate a bivariate isotropic or anisotropic Gaussian kernel.

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

Parameters
  • 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.

Returns

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

Return type

kernel (np.ndarray)

mmagic.datasets.transforms.blur_kernels.bivariate_generalized_gaussian(kernel_size, sig_x, sig_y=None, theta=None, beta=1, grid=None, is_isotropic=True)[source]

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.

Parameters
  • 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.

Returns

normalized kernel.

Return type

kernel (np.ndarray)

mmagic.datasets.transforms.blur_kernels.bivariate_plateau(kernel_size, sig_x, sig_y, theta, beta, grid=None, is_isotropic=True)[source]

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.

Parameters
  • 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.

Returns

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

Return type

kernel (np.ndarray)

mmagic.datasets.transforms.blur_kernels.random_bivariate_gaussian_kernel(kernel_size, sigma_x_range, sigma_y_range, rotation_range, noise_range=None, is_isotropic=True)[source]

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.

Parameters
  • 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.

Returns

The kernel whose parameters are sampled from the

specified range.

Return type

kernel (np.ndarray)

mmagic.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)[source]

Randomly generate bivariate generalized Gaussian kernels.

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

Parameters
  • 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.

Returns

Normalized kernel.

Return type

kernel (np.ndarray)

mmagic.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)[source]

Randomly generate bivariate plateau kernels.

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

Parameters
  • 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.

Returns

Plateau kernel.

Return type

kernel (np.ndarray)

mmagic.datasets.transforms.blur_kernels.random_circular_lowpass_kernel(omega_range, kernel_size, pad_to=0)[source]

Generate a 2D Sinc filter.

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

Parameters
  • 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.

Returns

The Sinc kernel with specified parameters.

Return type

kernel (np.ndarray)

mmagic.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)[source]

Randomly generate a kernel.

Parameters
  • 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.

Returns

The kernel whose parameters are sampled from the

specified range.

Return type

kernel (np.ndarray)

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.