pyiqa.matlab_utils.functions ============================ .. py:module:: pyiqa.matlab_utils.functions Module Contents --------------- .. 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:: dct(x, norm=None) 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' :returns: the DCT-II of the signal over the last dimension .. 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:: cov(tensor, rowvar=True, bias=False) Estimate a covariance matrix (np.cov) Ref: https://gist.github.com/ModarTensai/5ab449acba9df1a26c12060240773110 .. 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)