utils#

Module Contents#

Functions#

compute_pad_size(width)

Computes the pad size required for rotation / inverse rotation so that pad + rotate + inverse rotate + unpad = original object

compute_pad_size_padded(width)

Given a padded tensor, computes how much padding it has had

pad_object(object[, mode])

Pads an input tensor so that pad + rotate + inverse rotate + unpad = original object. This is useful for rotating objects without losing information at the edges.

unpad_object(object)

Given a padded object, removes the padding to return the original object

get_kernel_meshgrid(xv_input, yv_input, k_width)

Obtains a kernel meshgrid of given spatial width k_width (in same units as meshgrid). Enforces the kernel size is odd

utils.compute_pad_size(width)[source]#

Computes the pad size required for rotation / inverse rotation so that pad + rotate + inverse rotate + unpad = original object

Parameters:

width (int) – Width of input tensor (assumed to be square)

Returns:

How much to pad each side by

Return type:

int

utils.compute_pad_size_padded(width)[source]#

Given a padded tensor, computes how much padding it has had

Parameters:

width (int) – Width of input padded tensor (assumed square)

Returns:

How much padding was applied to the input tensor

Return type:

int

utils.pad_object(object, mode='constant')[source]#

Pads an input tensor so that pad + rotate + inverse rotate + unpad = original object. This is useful for rotating objects without losing information at the edges.

Parameters:
  • object (torch.Tensor) – Object to be padded

  • mode (str, optional) – Mode for extrapolation beyonf out of bounds. Defaults to ‘constant’.

Returns:

Padded object

Return type:

torch.Tensor

utils.unpad_object(object)[source]#

Given a padded object, removes the padding to return the original object

Parameters:

object (torch.Tensor) – Padded object

Returns:

Unpadded, original object

Return type:

torch.Tensor

utils.get_kernel_meshgrid(xv_input, yv_input, k_width)[source]#

Obtains a kernel meshgrid of given spatial width k_width (in same units as meshgrid). Enforces the kernel size is odd

Parameters:
  • xv_input (torch.Tensor) – Meshgrid x-coordinates corresponding to the input of some operator

  • yv_input (torch.Tensor) – Meshgrid y-coordinates corresponding to the input of some operator

  • k_width (float) – Width of kernel in same units as meshgrid

Returns:

Meshgrid of kernel

Return type:

tuple[torch.Tensor, torch.Tensor]