Misc API

Miscellaneous API.

Super-resolution

kiui.sr.sr(image: ndarray, scale: Literal[2, 4, 8] = 2, device=None)[source]

lazy load functional super-resolution API for convenience.

Parameters:
  • image (ndarray) – input image, uint8/float32 [H, W, 3]

  • scale (Literal[2, 4, 8], optional) – upscale factor. Defaults to 2.

  • device (torch.device, optional) – device to put SR models, if not provided, will try to use ‘cuda’. Defaults to None.

Returns:

super-resolutioned image, uint8/float32 [H * scale, W * scale, 3]

Return type:

ndarray

Grid-put

kiui.grid_put.grid_put(shape: Sequence[int], coords: Tensor, values: Tensor, mode: Literal[‘nearest’, ‘linear’, ‘linear-mipmap’] = 'linear-mipmap', min_resolution: int = 32, return_count: bool = False) Tensor[source]

put back values to an image according to the coords. inverse operation of F.grid_sample.

Parameters:
  • shape (Sequence[int]) – shape of the image, support 2D image and 3D volume, sequence of [D]

  • coords (Tensor) – coordinates, float [N, D] in [-1, 1].

  • values (Tensor) – values, float [N, C].

  • mode (str, Literal[‘nearest’, ‘linear’, ‘linear-mipmap’]) – interpolation mode, see https://github.com/ashawkey/grid_put for examples. Defaults to ‘linear-mipmap’.

  • min_resolution (int, optional) – minimal resolution for mipmap. Defaults to 32.

  • return_count (bool, optional) – whether to return the summed value and weights, instead of the divided results. Defaults to False.

Returns:

the restored image/volume, float [H, W, C]/[H, W, D, C].

Return type:

Tensor