cutcutcodec.core.analysis.video.complexity.dct.dct_matrix

cutcutcodec.core.analysis.video.complexity.dct.dct_matrix(size: Integral, dtype: dtype) Tensor[source]

Return the DCT-II matrix, including average coefficient.

The square matrix \(\boldsymbol{D} \in \mathcal M_{n,n}(\mathbb R)\) is defined as \(d_{ij} = \cos\left(\frac{\pi}{n}\left(i-1\right)\left(j-\frac{1}{2}\right)\right)\).

For a given “temporal” column vector \(\boldsymbol{x} \in \mathcal M_{n,1}(\mathbb R)\), the “spatial” column vector \(\boldsymbol{\hat{x}} \in \mathcal M_{n,1}(\mathbb R)\) is obtained with \(\boldsymbol{\hat{x}} = \boldsymbol{D}\boldsymbol{x}\).

Parameters

sizeint

The matrix size \(n\).

dtypetorch.dtype

The torch dtype of the matrix, float16, float32 or float64.

Returns

dtc_matrixtorch.Tensor

The 2d square matrix \(\boldsymbol{D}\) of the DCT-II coefficients.

Examples

>>> import torch
>>> from cutcutcodec.core.analysis.video.complexity.dct import dct_matrix
>>> dct_matrix(8, torch.float32)
tensor([[ 1.0000,  1.0000,  1.0000,  1.0000,  1.0000,  1.0000,  1.0000,  1.0000],
        [ 0.9808,  0.8315,  0.5556,  0.1951, -0.1951, -0.5556, -0.8315, -0.9808],
        [ 0.9239,  0.3827, -0.3827, -0.9239, -0.9239, -0.3827,  0.3827,  0.9239],
        [ 0.8315, -0.1951, -0.9808, -0.5556,  0.5556,  0.9808,  0.1951, -0.8315],
        [ 0.7071, -0.7071, -0.7071,  0.7071,  0.7071, -0.7071, -0.7071,  0.7071],
        [ 0.5556, -0.9808,  0.1951,  0.8315, -0.8315, -0.1951,  0.9808, -0.5556],
        [ 0.3827, -0.9239,  0.9239, -0.3827, -0.3827,  0.9239, -0.9239,  0.3827],
        [ 0.1951, -0.5556,  0.8315, -0.9808,  0.9808, -0.8315,  0.5556, -0.1951]])
>>> _ @ torch.sin(0.5 * torch.pi * torch.arange(8))[:, None]
tensor([[ 0.0000e+00],
        [ 1.0616e+00],
        [ 2.6822e-07],
        [ 2.1727e+00],
        [-2.8284e+00],
        [-1.4518e+00],
        [-2.9802e-07],
        [-2.1116e-01]])
>>>