Converts a PyTorch tensor image to a numpy image. In case the tensor is in the GPU, it will be copied back to CPU.

Parameters:tensor (torch.Tensor) – image of the form \((C, H, W)\).
Returns:image of the form \((H, W, C)\).
Return type:numpy.ndarray

Converts a numpy image to a PyTorch tensor image.

Parameters:image (numpy.ndarray) – image of the form \((H, W, C)\).
Returns:tensor of the form \((C, H, W)\).
Return type:torch.Tensor
create_meshgrid(height: int, width: int, normalized_coordinates: Optional[bool] = True)[source]

Generates a coordinate grid for an image.

When the flag normalized_coordinates is set to True, the grid is normalized to be in the range [-1,1] to be consistent with the pytorch function grid_sample.

  • height (int) – the image height (rows).
  • width (int) – the image width (cols).
  • normalized_coordinates (Optional[bool]) – wether to normalize coordinates in the range [-1, 1] in order to be consistent with the PyTorch function grid_sample.

returns a grid tensor with shape \((1, H, W, 2)\).

Return type: