pyiqa.archs.func_util

Module Contents

pyiqa.archs.func_util.EPS[source]
pyiqa.archs.func_util.preprocess_rgb(x, test_y_channel, data_range: float = 1, color_space='yiq')[source]

Preprocesses an RGB image tensor.

Parameters:
  • x (-) – The input RGB image tensor.

  • test_y_channel (-) – Whether to test the Y channel.

  • data_range (-) – The data range of the input tensor. Default is 1.

  • color_space (-) – The color space of the input tensor. Default is “yiq”.

Returns:

The preprocessed RGB image tensor.

Return type:

torch.Tensor

pyiqa.archs.func_util.extract_2d_patches(x, kernel, stride=1, dilation=1, padding='same')[source]

Extracts 2D patches from a 4D tensor.

Parameters:
  • x (-) – Input tensor of shape (batch_size, channels, height, width).

  • kernel (-) – Size of the kernel to be used for patch extraction.

  • stride (-) – Stride of the kernel. Default is 1.

  • dilation (-) – Dilation rate of the kernel. Default is 1.

  • padding (-) – Type of padding to be applied. Can be “same” or “none”. Default is “same”.

Returns:

Extracted patches tensor of shape (batch_size, num_patches, channels, kernel, kernel).

Return type:

torch.Tensor

pyiqa.archs.func_util.torch_cov(tensor, rowvar=True, bias=False)[source]

Estimate a covariance matrix (np.cov) Ref: https://gist.github.com/ModarTensai/5ab449acba9df1a26c12060240773110

pyiqa.archs.func_util.safe_sqrt(x: torch.Tensor) torch.Tensor[source]

Safe sqrt with EPS to ensure numeric stability.

Parameters:

x (torch.Tensor) – should be non-negative

pyiqa.archs.func_util.diff_round(x: torch.Tensor) torch.Tensor[source]

Differentiable round.

pyiqa.archs.func_util.normalize_img_with_gauss(img: torch.Tensor, kernel_size: int = 7, sigma: float = 7.0 / 6, C: int = 1, padding: str = 'same')[source]
pyiqa.archs.func_util.scharr_filter() torch.Tensor[source]

Utility function that returns a normalized 3x3 Scharr kernel in X direction :returns: Tensor with shape (1, 3, 3) :rtype: kernel

pyiqa.archs.func_util.gradient_map(x: torch.Tensor, kernels: torch.Tensor) torch.Tensor[source]

Compute gradient map for a given tensor and stack of kernels. :param x: Tensor with shape (N, C, H, W). :param kernels: Stack of tensors for gradient computation with shape (k_N, k_H, k_W)

Returns:

Gradients of x per-channel with shape (N, C, H, W)

pyiqa.archs.func_util.similarity_map(map_x: torch.Tensor, map_y: torch.Tensor, constant: float, alpha: float = 0.0) torch.Tensor[source]

Compute similarity_map between two tensors using Dice-like equation. :param map_x: Tensor with map to be compared :param map_y: Tensor with map to be compared :param constant: Used for numerical stability :param alpha: Masking coefficient. Subtracts - alpha * map_x * map_y from denominator and nominator

pyiqa.archs.func_util.ifftshift(x: torch.Tensor) torch.Tensor[source]

Similar to np.fft.ifftshift but applies to PyTorch Tensors

pyiqa.archs.func_util.get_meshgrid(size: Tuple[int, int]) torch.Tensor[source]

Return coordinate grid matrices centered at zero point. :param size: Shape of meshgrid to create

pyiqa.archs.func_util.estimate_ggd_param(x: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][source]

Estimate general gaussian distribution.

Parameters:

x (Tensor) – shape (b, 1, h, w)

pyiqa.archs.func_util.estimate_aggd_param(block: torch.Tensor, return_sigma=False) Tuple[torch.Tensor, torch.Tensor, torch.Tensor][source]

Estimate AGGD (Asymmetric Generalized Gaussian Distribution) parameters. :param block: Image block with shape (b, 1, h, w). :type block: Tensor

Returns:

alpha, beta_l and beta_r for the AGGD distribution (Estimating the parames in Equation 7 in the paper).

Return type:

Tensor