Skip to main content

dl::spatial

dl::spatial

Functions

Name
float continuous_image_to_tensor(float image_coord, int image_size, int tensor_size)
Map a continuous image-space coordinate to tensor space.
float continuous_tensor_to_image(float tensor_coord, int tensor_size, int image_size)
Map a continuous tensor-space coordinate to image space.
int discrete_image_to_tensor(int image_coord, int image_size, int tensor_size)
Nearest tensor index for an integer image pixel (mask encode / downsample).
int discrete_dest_to_source(int dest_coord, int source_size, int dest_size)
Nearest tensor index sampled when upsampling to a destination pixel (mask decode).
int discrete_tensor_nearest(float tensor_coord, int tensor_size)
Round a continuous tensor coordinate to the nearest discrete tensor index.

Functions Documentation

function continuous_image_to_tensor

float continuous_image_to_tensor(
    float image_coord,
    int image_size,
    int tensor_size
)

Map a continuous image-space coordinate to tensor space.

Parameters:

  • image_coord Coordinate along one axis in image space (may be fractional).
  • image_size Image extent along that axis (must be > 0).
  • tensor_size Tensor extent along that axis (must be > 0).

Return: Continuous tensor coordinate.

Precondition: image_size > 0 and tensor_size > 0

function continuous_tensor_to_image

float continuous_tensor_to_image(
    float tensor_coord,
    int tensor_size,
    int image_size
)

Map a continuous tensor-space coordinate to image space.

Parameters:

  • tensor_coord Coordinate along one axis in tensor space (may be fractional).
  • tensor_size Tensor extent along that axis (must be > 0).
  • image_size Image extent along that axis (must be > 0).

Return: Continuous image coordinate.

Precondition: tensor_size > 0 and image_size > 0

function discrete_image_to_tensor

int discrete_image_to_tensor(
    int image_coord,
    int image_size,
    int tensor_size
)

Nearest tensor index for an integer image pixel (mask encode / downsample).

Parameters:

  • image_coord Integer image pixel index along one axis.
  • image_size Image extent along that axis (must be > 0).
  • tensor_size Tensor extent along that axis (must be > 0).

Return: Clamped tensor index in [0, tensor_size - 1].

Precondition: image_size > 0 and tensor_size > 0

function discrete_dest_to_source

int discrete_dest_to_source(
    int dest_coord,
    int source_size,
    int dest_size
)

Nearest tensor index sampled when upsampling to a destination pixel (mask decode).

Parameters:

  • dest_coord Integer destination pixel index along one axis.
  • source_size Source (tensor) extent along that axis (must be > 0).
  • dest_size Destination (image) extent along that axis (must be > 0).

Return: Clamped source index in [0, source_size - 1].

Precondition: source_size > 0 and dest_size > 0

Equivalent to [map_dest_to_source](/api_generated/Files/mask__utils_8cpp.md#function-map-dest-to-source) in [mask_utils.hpp](/api_generated/Files/mask__utils_8hpp.md#file-mask-utils.hpp) with std::lround.

function discrete_tensor_nearest

int discrete_tensor_nearest(
    float tensor_coord,
    int tensor_size
)

Round a continuous tensor coordinate to the nearest discrete tensor index.

Parameters:

  • tensor_coord Continuous tensor coordinate along one axis.
  • tensor_size Tensor extent along that axis (must be > 0).

Return: Clamped index in [0, tensor_size - 1].

Precondition: tensor_size > 0


Updated on 2026-11-13 at 20:25:42 +0000