:py:mod:`utils` =============== .. py:module:: utils Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: utils.compute_pad_size utils.compute_pad_size_padded utils.pad_object utils.unpad_object utils.get_kernel_meshgrid .. py:function:: compute_pad_size(width) Computes the pad size required for rotation / inverse rotation so that pad + rotate + inverse rotate + unpad = original object :param width: Width of input tensor (assumed to be square) :type width: int :returns: How much to pad each side by :rtype: int .. py:function:: compute_pad_size_padded(width) Given a padded tensor, computes how much padding it has had :param width: Width of input padded tensor (assumed square) :type width: int :returns: How much padding was applied to the input tensor :rtype: int .. py:function:: pad_object(object, mode='constant') 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. :param object: Object to be padded :type object: torch.Tensor :param mode: Mode for extrapolation beyonf out of bounds. Defaults to 'constant'. :type mode: str, optional :returns: Padded object :rtype: torch.Tensor .. py:function:: unpad_object(object) Given a padded object, removes the padding to return the original object :param object: Padded object :type object: torch.Tensor :returns: Unpadded, original object :rtype: torch.Tensor .. py:function:: 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 :param xv_input: Meshgrid x-coordinates corresponding to the input of some operator :type xv_input: torch.Tensor :param yv_input: Meshgrid y-coordinates corresponding to the input of some operator :type yv_input: torch.Tensor :param k_width: Width of kernel in same units as meshgrid :type k_width: float :returns: Meshgrid of kernel :rtype: tuple[torch.Tensor, torch.Tensor]