kornia.geometry.grid¶
- kornia.geometry.grid.create_meshgrid(height, width, normalized_coordinates=True, device=None, dtype=None)[source]¶
Generate a coordinate grid for an image.
When the flag
normalized_coordinatesis set to True, the grid is normalized to be in the range \([-1,1]\) to be consistent with the pytorch functiontorch.nn.functional.grid_sample().- Parameters:
height (
int) – the image height (rows).width (
int) – the image width (cols).normalized_coordinates (
bool, optional) – whether to normalize coordinates in the range \([-1,1]\) in order to be consistent with the PyTorch functiontorch.nn.functional.grid_sample(). Default:Truedevice (
Optional[device], optional) – the device on which the grid will be generated. Default:Nonedtype (
Optional[dtype], optional) – the data type of the generated grid. Default:None
- Return type:
- Returns:
grid tensor with shape \((1, H, W, 2)\).
Example
>>> create_meshgrid(2, 2) tensor([[[[-1., -1.], [ 1., -1.]], [[-1., 1.], [ 1., 1.]]]])
>>> create_meshgrid(2, 2, normalized_coordinates=False) tensor([[[[0., 0.], [1., 0.]], [[0., 1.], [1., 1.]]]])
- kornia.geometry.grid.create_meshgrid3d(depth, height, width, normalized_coordinates=True, device=None, dtype=None)[source]¶
Generate a coordinate grid for an image.
When the flag
normalized_coordinatesis set to True, the grid is normalized to be in the range \([-1,1]\) to be consistent with the pytorch functiontorch.nn.functional.grid_sample().- Parameters:
depth (
int) – the image depth (channels).height (
int) – the image height (rows).width (
int) – the image width (cols).normalized_coordinates (
bool, optional) – whether to normalize coordinates in the range \([-1,1]\) in order to be consistent with the PyTorch functiontorch.nn.functional.grid_sample(). Default:Truedevice (
Optional[device], optional) – the device on which the grid will be generated. Default:Nonedtype (
Optional[dtype], optional) – the data type of the generated grid. Default:None
- Return type:
- Returns:
grid tensor with shape \((1, D, H, W, 3)\).