cutcutcodec.core.analysis.video.complexity.rms_sobel

cutcutcodec.core.analysis.video.complexity.rms_sobel(img: Tensor) Tensor[source]

Compute the spacial root mean square sobel gratient complexity for the image.

Note

It comes from ENCODING TIME AND ENERGY MODEL FOR SVT-AV1 BASED ON VIDEO COMPLEXITY.

This function implements the following formula:

\[\begin{split}\begin{cases} C_{sob} = \sqrt{ \frac{1}{(h-2)(w-2)} \sum_{\boldsymbol{i} \in [\![1, h-2]\!] \times [\![1, w-2]\!]}\left( \boldsymbol{G_x}^2(\boldsymbol{i}) + \boldsymbol{G_y}^2(\boldsymbol{i}) \right) } \\ \boldsymbol{G_x} = \boldsymbol{S} \star \boldsymbol{Y} \\ \boldsymbol{G_y} = \boldsymbol{S}^\intercal \star \boldsymbol{Y} \\ \boldsymbol{S} = \begin{pmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \\ \end{pmatrix} \end{cases}\end{split}\]
With:
  • \(\star\) the correlation product along the axis height and width.

  • \(\boldsymbol{Y}\) the Y layer of the image as a 2d matrix.

Parameters

imgarraylike

The Y[UV] images, of shape ([*batch], [1], height, width, [channels]). Only the Y component is used. It has to be in range [0, 1]. As there is no padding on the edges, the image must be at least 3x3 pixels.

Returns

rms_sobelarraylike

The \(C_{sob} \in \mathbb{R}^+\) scalar for each image (of shape batch).

Examples

>>> import numpy as np
>>> from cutcutcodec.core.analysis.video.complexity import rms_sobel
>>> np.random.seed(0)
>>> img = np.random.random((720, 1080, 3))  # It could also be a torch array list...
>>> rms_sobel(img).round(1)
np.float64(1.4)
>>>