pyiqa.matlab_utils ================== .. py:module:: pyiqa.matlab_utils .. autoapi-nested-parse:: This folder contains pytorch implementations of matlab functions. And should produce the same results as matlab. Note: to enable GPU acceleration, all functions take batched tensors as inputs, and return batched results. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyiqa/matlab_utils/functions/index /autoapi/pyiqa/matlab_utils/math_util/index /autoapi/pyiqa/matlab_utils/nss_feature/index /autoapi/pyiqa/matlab_utils/padding/index /autoapi/pyiqa/matlab_utils/resize/index /autoapi/pyiqa/matlab_utils/scfpyr_util/index Package Contents ---------------- .. py:function:: imresize(x: torch.Tensor, scale: Optional[float] = None, sizes: Optional[Tuple[int, int]] = None, kernel: Union[str, torch.Tensor] = 'cubic', sigma: float = 2, rotation_degree: float = 0, padding_type: str = 'reflect', antialiasing: bool = True) -> torch.Tensor :param x: :type x: torch.Tensor :param scale: :type scale: float :param sizes: :type sizes: tuple(int, int) :param kernel: :type kernel: str, default='cubic' :param sigma: :type sigma: float, default=2 :param rotation_degree: :type rotation_degree: float, default=0 :param padding_type: :type padding_type: str, default='reflect' :param antialiasing: :type antialiasing: bool, default=True :rtype: torch.Tensor .. py:class:: ExactPadding2d(kernel, stride=1, dilation=1, mode='same') Bases: :py:obj:`torch.nn.Module` This function calculate exact padding values for 4D tensor inputs, and support the same padding mode as tensorflow. :param kernel: kernel size. :type kernel: int or tuple :param stride: stride size. :type stride: int or tuple :param dilation: dilation size, default with 1. :type dilation: int or tuple :param mode: padding mode can be ('same', 'symmetric', 'replicate', 'circular') :type mode: srt .. py:method:: forward(x) .. py:function:: symm_pad(im: torch.Tensor, padding: Tuple[int, int, int, int]) Symmetric padding same as tensorflow. Ref: https://discuss.pytorch.org/t/symmetric-padding/19866/3 .. py:function:: fspecial(size=None, sigma=None, channels=1, filter_type='gaussian') Function same as 'fspecial' in MATLAB, only support gaussian now. :param size: size of window :type size: int or tuple :param sigma: sigma of gaussian :type sigma: float :param channels: channels of output :type channels: int .. py:function:: conv2d(input, weight, bias=None, stride=1, padding='same', dilation=1, groups=1) Matlab like conv2, weights needs to be flipped. :param input: (b, c, h, w) :type input: tensor :param weight: (out_ch, in_ch, kh, kw), conv weight :type weight: tensor :param bias: bias :type bias: bool or None :param stride: conv stride :type stride: int or tuple :param padding: padding mode :type padding: str :param dilation: conv dilation :type dilation: int .. py:function:: imfilter(input, weight, bias=None, stride=1, padding='same', dilation=1, groups=1) imfilter same as matlab. :param input: (b, c, h, w) tensor to be filtered :type input: tensor :param weight: (out_ch, in_ch, kh, kw) filter kernel :type weight: tensor :param padding: padding mode :type padding: str :param dilation: dilation of conv :type dilation: int :param groups: groups of conv :type groups: int .. py:function:: filter2(input, weight, shape='same') .. py:function:: dct2d(x, norm='ortho') 2-dimensional Discrete Cosine Transform, Type II (a.k.a. the DCT) For the meaning of the parameter `norm`, see: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.fftpack.dct.html :param x: the input signal :param norm: the normalization, None or 'ortho' :return: the DCT-II of the signal over the last 2 dimensions .. py:function:: fitweibull(x, iters=50, eps=0.01) Simulate wblfit function in matlab. ref: https://github.com/mlosch/python-weibullfit/blob/master/weibull/backend_pytorch.py Fits a 2-parameter Weibull distribution to the given data using maximum-likelihood estimation. :param x (tensor): (B, N), batch of samples from an (unknown) distribution. Each value must satisfy x > 0. :param iters: Maximum number of iterations :param eps: Stopping criterion. Fit is stopped ff the change within two iterations is smaller than eps. :param use_cuda: Use gpu :return: Tuple (Shape, Scale) which can be (NaN, NaN) if a fit is impossible. Impossible fits may be due to 0-values in x. .. py:function:: nancov(x) Calculate nancov for batched tensor, rows that contains nan value will be removed. :param x: (B, row_num, feat_dim) :type x: tensor :returns: (B, feat_dim, feat_dim) :rtype: cov (tensor) .. py:function:: nanmean(v, *args, inplace=False, **kwargs) nanmean same as matlab function: calculate mean values by removing all nan. .. py:function:: im2col(x, kernel, mode='sliding') simple im2col as matlab :param x: shape (b, c, h, w) :type x: Tensor :param kernel: kernel size :type kernel: int :param mode: - sliding (default): rearranges sliding image neighborhoods of kernel size into columns with no zero-padding - distinct: rearranges discrete image blocks of kernel size into columns, zero pad right and bottom if necessary :type mode: string :returns: (b, h * w / kernel **2, kernel * kernel) :rtype: flatten patch (Tensor) .. py:function:: blockproc(x, kernel, fun, border_size=None, pad_partial=False, pad_method='zero', **func_args) blockproc function like matlab Difference: - Partial blocks is discarded (if exist) for fast GPU process. :param x: shape (b, c, h, w) :type x: tensor :param kernel: block size :type kernel: int or tuple :param func: function to process each block :type func: function :param border_size: border pixels to each block :type border_size: int or tuple :param pad_partial: pad partial blocks to make them full-sized, default False :param pad_method: [zero, replicate, symmetric] how to pad partial block when pad_partial is set True :returns: concatenated results of each block :rtype: results (tensor) .. py:class:: SCFpyr_PyTorch(height=5, nbands=4, scale_factor=2, device=None) Bases: :py:obj:`object` This is a modified version of buildSFpyr, that constructs a complex-valued steerable pyramid using Hilbert-transform pairs of filters. Note that the imaginary parts will *not* be steerable. Pytorch version >= 1.8.0 .. py:method:: build(im_batch) Decomposes a batch of images into a complex steerable pyramid. The pyramid typically has ~4 levels and 4-8 orientations. :param im_batch: Batch of images of shape [N,C,H,W] :type im_batch: torch.Tensor :returns: list containing torch.Tensor objects storing the pyramid :rtype: pyramid .. py:class:: ExactPadding2d(kernel, stride=1, dilation=1, mode='same') Bases: :py:obj:`torch.nn.Module` This function calculate exact padding values for 4D tensor inputs, and support the same padding mode as tensorflow. :param kernel: kernel size. :type kernel: int or tuple :param stride: stride size. :type stride: int or tuple :param dilation: dilation size, default with 1. :type dilation: int or tuple :param mode: padding mode can be ('same', 'symmetric', 'replicate', 'circular') :type mode: srt .. py:method:: forward(x) .. py:function:: exact_padding_2d(x, kernel, stride=1, dilation=1, mode='same') .. py:function:: symm_pad(im: torch.Tensor, padding: Tuple[int, int, int, int]) Symmetric padding same as tensorflow. Ref: https://discuss.pytorch.org/t/symmetric-padding/19866/3