pyiqa.archs.func_util ===================== .. py:module:: pyiqa.archs.func_util Module Contents --------------- .. py:data:: EPS .. py:function:: preprocess_rgb(x, test_y_channel, data_range: float = 1, color_space='yiq') Preprocesses an RGB image tensor. :param - x: The input RGB image tensor. :type - x: torch.Tensor :param - test_y_channel: Whether to test the Y channel. :type - test_y_channel: bool :param - data_range: The data range of the input tensor. Default is 1. :type - data_range: float :param - color_space: The color space of the input tensor. Default is "yiq". :type - color_space: str :returns: The preprocessed RGB image tensor. :rtype: torch.Tensor .. py:function:: extract_2d_patches(x, kernel, stride=1, dilation=1, padding='same') Extracts 2D patches from a 4D tensor. :param - x: Input tensor of shape (batch_size, channels, height, width). :type - x: torch.Tensor :param - kernel: Size of the kernel to be used for patch extraction. :type - kernel: int :param - stride: Stride of the kernel. Default is 1. :type - stride: int :param - dilation: Dilation rate of the kernel. Default is 1. :type - dilation: int :param - padding: Type of padding to be applied. Can be "same" or "none". Default is "same". :type - padding: str :returns: Extracted patches tensor of shape (batch_size, num_patches, channels, kernel, kernel). :rtype: torch.Tensor .. py:function:: torch_cov(tensor, rowvar=True, bias=False) Estimate a covariance matrix (np.cov) Ref: https://gist.github.com/ModarTensai/5ab449acba9df1a26c12060240773110 .. py:function:: safe_sqrt(x: torch.Tensor) -> torch.Tensor Safe sqrt with EPS to ensure numeric stability. :param x: should be non-negative :type x: torch.Tensor .. py:function:: diff_round(x: torch.Tensor) -> torch.Tensor Differentiable round. .. py:function:: normalize_img_with_gauss(img: torch.Tensor, kernel_size: int = 7, sigma: float = 7.0 / 6, C: int = 1, padding: str = 'same') .. py:function:: scharr_filter() -> torch.Tensor Utility function that returns a normalized 3x3 Scharr kernel in X direction :returns: Tensor with shape (1, 3, 3) :rtype: kernel .. py:function:: gradient_map(x: torch.Tensor, kernels: torch.Tensor) -> torch.Tensor 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) .. py:function:: similarity_map(map_x: torch.Tensor, map_y: torch.Tensor, constant: float, alpha: float = 0.0) -> torch.Tensor 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 .. py:function:: ifftshift(x: torch.Tensor) -> torch.Tensor Similar to np.fft.ifftshift but applies to PyTorch Tensors .. py:function:: get_meshgrid(size: Tuple[int, int]) -> torch.Tensor Return coordinate grid matrices centered at zero point. :param size: Shape of meshgrid to create .. py:function:: estimate_ggd_param(x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor] Estimate general gaussian distribution. :param x: shape (b, 1, h, w) :type x: Tensor .. py:function:: estimate_aggd_param(block: torch.Tensor, return_sigma=False) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor] 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). :rtype: Tensor