pyiqa.matlab_utils.functions¶
Module Contents¶
- pyiqa.matlab_utils.functions.fspecial(size=None, sigma=None, channels=1, filter_type='gaussian')[source]¶
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
- pyiqa.matlab_utils.functions.conv2d(input, weight, bias=None, stride=1, padding='same', dilation=1, groups=1)[source]¶
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
- pyiqa.matlab_utils.functions.imfilter(input, weight, bias=None, stride=1, padding='same', dilation=1, groups=1)[source]¶
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
- pyiqa.matlab_utils.functions.dct(x, norm=None)[source]¶
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
- pyiqa.matlab_utils.functions.dct2d(x, norm='ortho')[source]¶
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
- pyiqa.matlab_utils.functions.fitweibull(x, iters=50, eps=0.01)[source]¶
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.
- pyiqa.matlab_utils.functions.cov(tensor, rowvar=True, bias=False)[source]¶
Estimate a covariance matrix (np.cov) Ref: https://gist.github.com/ModarTensai/5ab449acba9df1a26c12060240773110
- pyiqa.matlab_utils.functions.nancov(x)[source]¶
Calculate nancov for batched tensor, rows that contains nan value will be removed.
- Parameters:
x (tensor) – (B, row_num, feat_dim)
- Returns:
(B, feat_dim, feat_dim)
- Return type:
cov (tensor)
- pyiqa.matlab_utils.functions.nanmean(v, *args, inplace=False, **kwargs)[source]¶
nanmean same as matlab function: calculate mean values by removing all nan.
- pyiqa.matlab_utils.functions.im2col(x, kernel, mode='sliding')[source]¶
simple im2col as matlab
- Parameters:
x (Tensor) – shape (b, c, h, w)
kernel (int) – kernel size
mode (string) –
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
- Returns:
(b, h * w / kernel **2, kernel * kernel)
- Return type:
flatten patch (Tensor)
- pyiqa.matlab_utils.functions.blockproc(x, kernel, fun, border_size=None, pad_partial=False, pad_method='zero', **func_args)[source]¶
blockproc function like matlab
- Difference:
Partial blocks is discarded (if exist) for fast GPU process.
- Parameters:
x (tensor) – shape (b, c, h, w)
kernel (int or tuple) – block size
func (function) – function to process each block
border_size (int or tuple) – border pixels to each block
pad_partial – pad partial blocks to make them full-sized, default False
pad_method – [zero, replicate, symmetric] how to pad partial block when pad_partial is set True
- Returns:
concatenated results of each block
- Return type:
results (tensor)