Source code for cutcutcodec.core.analysis.video.complexity.dct

"""Compute a differenciable batched torch spacial dtc complexity."""

import torch

from cutcutcodec.core.opti.parallel.threading import TorchThreads

from .utils import batched_frames


[docs] @batched_frames def spacial_dct(img: torch.Tensor, threads: int = 0) -> torch.Tensor: r"""Compute the spacial dct complexity for the image. Parameters ---------- img : arraylike 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 64x64 pixels. threads : int, optional Defines the number of threads. The value -1 means that the function uses as many calculation threads as there are cores. The default value (0) allows the same behavior as (-1) if the function is called in the main thread, otherwise (1) to avoid nested threads. Any other positive value corresponds to the number of threads used. Returns ------- spacial_dct : arraylike The :math:`C_{sob} \in \mathbb{R}^+` scalar for each image (of shape batch). Examples -------- >>> import numpy as np >>> from cutcutcodec.core.analysis.video.complexity import spacial_dct >>> np.random.seed(0) >>> img = np.random.random((720, 1080, 3)) # It could also be a torch array list... >>> spacial_dct(img).round(1) np.float64(1.4) >>> """ _, _, height, width, _ = img.shape assert (height, width) >= (64, 64), f"the image {img.shape} is to small" with TorchThreads(threads): raise NotImplementedError