π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
add auto-images in geometry transform module (#1131)
Edgar Riba5b8ae73063f3
diff --git a/docs/generate_example_images.py b/docs/generate_example_images.pyindex 2ac278465..552f184f7 100644--- a/docs/generate_example_images.py+++ b/docs/generate_example_images.py@@ -36,6 +36,7 @@ def main():BASE_IMAGE_URL3: str = "https://raw.githubusercontent.com/kornia/data/main/girona.png" # enhanceBASE_IMAGE_URL4: str = "https://raw.githubusercontent.com/kornia/data/main/baby_giraffe.png" # morphologyBASE_IMAGE_URL5: str = "https://raw.githubusercontent.com/kornia/data/main/persistencia_memoria.jpg" # filters+ BASE_IMAGE_URL6: str = "https://raw.githubusercontent.com/kornia/data/main/delorean.png" # geometryOUTPUT_PATH = Path(__file__).absolute().parent / "source/_static/img"os.makedirs(OUTPUT_PATH, exist_ok=True)@@ -45,6 +46,7 @@ def main():img3 = read_img_from_url(BASE_IMAGE_URL3, img1.shape[-2:])img4 = read_img_from_url(BASE_IMAGE_URL4)img5 = read_img_from_url(BASE_IMAGE_URL5, (234, 320))+ img6 = read_img_from_url(BASE_IMAGE_URL6)# TODO: make this more generic for modules out of kornia.augmentation# Dictionary containing the transforms to generate the sample images:@@ -52,7 +54,7 @@ def main():# Value: (parameters, num_samples, seed)mod = importlib.import_module("kornia.augmentation")augmentations_list: dict = {- "CenterCrop": ((96, 96), 1, 2018),+ "CenterCrop": ((184, 184), 1, 2018),"ColorJitter": ((0.3, 0.3, 0.3, 0.3), 2, 2018),"RandomAffine": (((-15.0, 20.0), (0.1, 0.1), (0.7, 1.3), 20), 2, 2019),"RandomBoxBlur": (((7, 7),), 1, 2020),@@ -90,7 +92,10 @@ def main():out = aug(img_in)if aug_name == "CenterCrop":- out = K.geometry.resize(out, img_in.shape[-2:])+ h, w = img1.shape[-2:]+ h_new, w_new = out.shape[-2:]+ h_dif, w_dif = int(h - h_new), int(w - w_new)+ out = torch.nn.functional.pad(out, (w_dif // 2, w_dif // 2, 0, h_dif))out = torch.cat([img_in[0], *[out[i] for i in range(out.size(0))]], dim=-1)# save the output image@@ -257,6 +262,78 @@ def main():sig = f"{fn_name}({', '.join([str(a) for a in args])})"print(f"Generated image example for {fn_name}. {sig}")+ # korna.geometry.transform module+ mod = importlib.import_module("kornia.geometry.transform")+ h, w = img6.shape[-2:]++ def _get_tps_args():+ src = torch.tensor([[[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, -1.0], [0.0, 0.0]]]).repeat(2, 1, 1) # Bx5x2+ dst = src + torch.distributions.Uniform(-0.2, 0.2).rsample((2, 5, 2))+ kernel, affine = K.geometry.transform.get_tps_transform(dst, src)+ return src, kernel, affine++ transforms: dict = {+ "warp_affine": (+ (+ K.geometry.transform.get_affine_matrix2d(+ translations=torch.zeros(2, 2),+ center=(torch.tensor([w, h]) / 2).repeat(2, 1),+ scale=torch.distributions.Uniform(0.5, 1.5).rsample((2, 2)),+ angle=torch.tensor([-25.0, 25.0]),+ )[:, :2, :3],+ (h, w),+ ),+ 2,+ ),+ "remap": (+ (+ *(K.utils.create_meshgrid(h, w, normalized_coordinates=True) - 0.25).unbind(-1),+ 'bilinear',+ 'zeros',+ True,+ True,+ ),+ 1,+ ),+ "warp_image_tps": ((_get_tps_args()), 2),+ "rotate": ((torch.tensor([-15.0, 25.0]),), 2),+ "translate": ((torch.tensor([[10.0, -15], [50.0, -25.0]]),), 2),+ "scale": ((torch.tensor([[0.5, 1.25], [1.0, 1.5]]),), 2),+ "shear": ((torch.tensor([[0.1, -0.2], [-0.2, 0.1]]),), 2),+ "rot180": ((), 1),+ "hflip": ((), 1),+ "vflip": ((), 1),+ "resize": (((120, 220),), 1),+ "rescale": ((0.5,), 1),+ "elastic_transform2d": ((torch.rand(1, 2, h, w) * 2 - 1, (63, 63), (32, 32), (4.0, 4.0)), 1),+ "pyrdown": ((), 1),+ "pyrup": ((), 1),+ "build_pyramid": ((3,), 1),+ }+ # ITERATE OVER THE TRANSFORMS+ for fn_name, (args, num_samples) in transforms.items():+ img_in = img6.repeat(num_samples, 1, 1, 1)+ args_in = (img_in, *args)+ # import function and apply+ fn = getattr(mod, fn_name)+ out = fn(*args_in)+ if fn_name in ("resize", "rescale", "pyrdown", "pyrup"):+ h_new, w_new = out.shape[-2:]+ out = torch.nn.functional.pad(out, (0, (w - w_new), 0, (h - h_new)))+ if fn_name == "build_pyramid":+ _out = []+ for pyr in out[1:]:+ h_new, w_new = pyr.shape[-2:]+ out_tmp = torch.nn.functional.pad(pyr, (0, (w - w_new), 0, (h - h_new)))+ _out.append(out_tmp)+ out = torch.cat(_out)+ # save the output image+ out = torch.cat([img_in[0], *[out[i] for i in range(out.size(0))]], dim=-1)+ out_np = K.utils.tensor_to_image((out * 255.0).byte())+ cv2.imwrite(str(OUTPUT_PATH / f"{fn_name}.png"), out_np)+ sig = f"{fn_name}({', '.join([str(a) for a in args])})"+ print(f"Generated image example for {fn_name}. {sig}")+if __name__ == "__main__":main()diff --git a/docs/source/geometry.transform.rst b/docs/source/geometry.transform.rstindex ca741dedf..d94e3f8f3 100644--- a/docs/source/geometry.transform.rst+++ b/docs/source/geometry.transform.rst@@ -12,10 +12,28 @@ Warp operators.. autofunction:: warp_perspective3d.. autofunction:: warp_affine.. autofunction:: warp_affine3d-.. autofunction:: warp_points_tps.. autofunction:: warp_image_tps+.. autofunction:: warp_points_tps.. autofunction:: remap+Image 2d transforms+-------------------++.. autofunction:: affine+.. autofunction:: rotate+.. autofunction:: translate+.. autofunction:: scale+.. autofunction:: shear+.. autofunction:: hflip+.. autofunction:: vflip+.. autofunction:: rot180+.. autofunction:: resize+.. autofunction:: rescale+.. autofunction:: elastic_transform2d+.. autofunction:: pyrdown+.. autofunction:: pyrup+.. autofunction:: build_pyramid+Matrix transformations----------------------@@ -47,24 +65,6 @@ Bounding Box.. autofunction:: infer_box_shape.. autofunction:: validate_bboxes-Image 2d transforms----------------------.. autofunction:: affine-.. autofunction:: rotate-.. autofunction:: translate-.. autofunction:: scale-.. autofunction:: shear-.. autofunction:: hflip-.. autofunction:: vflip-.. autofunction:: rot180-.. autofunction:: resize-.. autofunction:: rescale-.. autofunction:: elastic_transform2d-.. autofunction:: pyrdown-.. autofunction:: pyrup-.. autofunction:: build_pyramid-Module------diff --git a/kornia/geometry/transform/affwarp.py b/kornia/geometry/transform/affwarp.pyindex 07f7c3a47..15bc0cab8 100644--- a/kornia/geometry/transform/affwarp.py+++ b/kornia/geometry/transform/affwarp.py@@ -125,18 +125,19 @@ def affine() -> torch.Tensor:r"""Apply an affine transformation to the image.+ .. image:: _static/img/warp_affine.png+Args:- tensor (torch.Tensor): The image tensor to be warped in shapes of+ tensor: The image tensor to be warped in shapes of:math:`(H, W)`, :math:`(D, H, W)` and :math:`(B, C, H, W)`.- matrix (torch.Tensor): The 2x3 affine transformation matrix.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ matrix: The 2x3 affine transformation matrix.+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The warped image with the same shape as the input.+ The warped image with the same shape as the input.Example:>>> img = torch.rand(1, 2, 3, 5)@@ -176,17 +177,17 @@ def affine3d(r"""Apply an affine transformation to the 3d volume.Args:- tensor (torch.Tensor): The image tensor to be warped in shapes of+ tensor: The image tensor to be warped in shapes of:math:`(D, H, W)`, :math:`(C, D, H, W)` and :math:`(B, C, D, H, W)`.- matrix (torch.Tensor): The affine transformation matrix with shape :math:`(B, 3, 4)`.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: False.+ matrix: The affine transformation matrix with shape :math:`(B, 3, 4)`.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ `` 'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The warped image.+ The warped image.Example:>>> img = torch.rand(1, 2, 4, 3, 5)@@ -229,23 +230,25 @@ def rotate(padding_mode: str = 'zeros',align_corners: Optional[bool] = None,) -> torch.Tensor:- r"""Rotate the tensor anti-clockwise about the centre.+ r"""Rotate the tensor anti-clockwise about the center.++ .. image:: _static/img/rotate.pngArgs:- tensor (torch.Tensor): The image tensor to be warped in shapes of :math:`(B, C, H, W)`.- angle (torch.Tensor): The angle through which to rotate. The tensor+ tensor: The image tensor to be warped in shapes of :math:`(B, C, H, W)`.+ angle: The angle through which to rotate. The tensormust have a shape of (B), where B is batch size.- center (torch.Tensor): The center through which to rotate. The tensor+ center: The center through which to rotate. The tensormust have a shape of (B, 2), where B is batch size and lastdimension contains cx and cy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The rotated tensor with shape as input.+ The rotated tensor with shape as input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -293,21 +296,21 @@ def rotate3d(r"""Rotate 3D the tensor anti-clockwise about the centre.Args:- tensor (torch.Tensor): The image tensor to be warped in shapes of :math:`(B, C, D, H, W)`.- yaw(torch.Tensor): The yaw angle through which to rotate. The tensor+ tensor: The image tensor to be warped in shapes of :math:`(B, C, D, H, W)`.+ yaw: The yaw angle through which to rotate. The tensormust have a shape of (B), where B is batch size.- pitch (torch.Tensor): The pitch angle through which to rotate. The tensor+ pitch: The pitch angle through which to rotate. The tensormust have a shape of (B), where B is batch size.- roll (torch.Tensor): The roll angle through which to rotate. The tensor+ roll: The roll angle through which to rotate. The tensormust have a shape of (B), where B is batch size.- center (torch.Tensor): The center through which to rotate. The tensor+ center: The center through which to rotate. The tensormust have a shape of (B, 2), where B is batch size and lastdimension contains cx and cy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: False.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:torch.Tensor: The rotated tensor with shape as input.@@ -355,19 +358,21 @@ def translate() -> torch.Tensor:r"""Translate the tensor in pixel units.+ .. image:: _static/img/translate.png+Args:- tensor (torch.Tensor): The image tensor to be warped in shapes of :math:`(B, C, H, W)`.- translation (torch.Tensor): tensor containing the amount of pixels to+ tensor: The image tensor to be warped in shapes of :math:`(B, C, H, W)`.+ translation: tensor containing the amount of pixels totranslate in the x and y direction. The tensor must have a shape of(B, 2), where B is batch size, last dimension contains dx dy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The translated tensor with shape as input.+ The translated tensor with shape as input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -402,23 +407,25 @@ def scale() -> torch.Tensor:r"""Scale the tensor by a factor.+ .. image:: _static/img/scale.png+Args:- tensor (torch.Tensor): The image tensor to be warped in shapes of :math:`(B, C, H, W)`.- scale_factor (torch.Tensor): The scale factor apply. The tensor+ tensor: The image tensor to be warped in shapes of :math:`(B, C, H, W)`.+ scale_factor: The scale factor apply. The tensormust have a shape of (B) or (B, 2), where B is batch size.If (B), isotropic scaling will perform.If (B, 2), x-y-direction specific scaling will perform.- center (torch.Tensor): The center through which to scale. The tensor+ center: The center through which to scale. The tensormust have a shape of (B, 2), where B is batch size and lastdimension contains cx and cy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The scaled tensor with the same shape as the input.+ The scaled tensor with the same shape as the input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -460,19 +467,21 @@ def shear() -> torch.Tensor:r"""Shear the tensor.+ .. image:: _static/img/shear.png+Args:- tensor (torch.Tensor): The image tensor to be skewed with shape of :math:`(B, C, H, W)`.- shear (torch.Tensor): tensor containing the angle to shear+ tensor: The image tensor to be skewed with shape of :math:`(B, C, H, W)`.+ shear: tensor containing the angle to shearin the x and y direction. The tensor must have a shape of(B, 2), where B is batch size, last dimension contains shx shy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The skewed tensor with shape same as the input.+ The skewed tensor with shape same as the input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -520,25 +529,25 @@ def resize() -> torch.Tensor:r"""Resize the input torch.Tensor to the given size.+ .. image:: _static/img/resize.png+Args:- tensor (torch.Tensor): The image tensor to be skewed with shape of :math:`(..., H, W)`.+ tensor: The image tensor to be skewed with shape of :math:`(..., H, W)`.`...` means there can be any number of dimensions.- size (int, tuple(int, int)): Desired output size. If size is a sequence like (h, w),+ size: Desired output size. If size is a sequence like (h, w),output size will be matched to this. If size is an int, smaller edge of the image willbe matched to this number. i.e, if height > width, then image will be rescaledto (size * height / width, size)- interpolation (str): algorithm used for upsampling: 'nearest' | 'linear' | 'bilinear' |- 'bicubic' | 'trilinear' | 'area'. Default: 'bilinear'.- align_corners(bool): interpolation flag. Default: None. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail- side (str): Corresponding side if ``size`` is an integer. Can be one of ``"short"``, ``"long"``, ``"vert"``,- or ``"horz"``. Defaults to ``"short"``.- antialias (bool): if True, then image will be filtered with Gaussian before downscaling.- No effect for upscaling. Default: False-+ interpolation: algorithm used for upsampling: ``'nearest'`` | ``'linear'`` | ``'bilinear'`` |+ 'bicubic' | 'trilinear' | 'area'.+ align_corners: interpolation flag.+ side: Corresponding side if ``size`` is an integer. Can be one of ``'short'``, ``'long'``, ``'vert'``,+ or ``'horz'``.+ antialias: if True, then image will be filtered with Gaussian before downscaling.+ No effect for upscaling.Returns:- torch.Tensor: The resized tensor with the shape as the specified size.+ The resized tensor with the shape as the specified size.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -588,19 +597,22 @@ def rescale() -> torch.Tensor:r"""Rescale the input torch.Tensor with the given factor.+ .. image:: _static/img/rescale.png+Args:- input(torch.Tensor): The image tensor to be scale with shape of :math:`(B, C, H, W)`.- interpolation (str): algorithm used for upsampling: 'nearest' | 'linear' | 'bilinear' |- 'bicubic' | 'trilinear' | 'area'. Default: 'bilinear'.- align_corners(bool): interpolation flag. Default: None. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail- side (str): Corresponding side if ``size`` is an integer. Can be one of ``"short"``, ``"long"``, ``"vert"``,- or ``"horz"``. Defaults to ``"short"``.- antialias (bool): if True, then image will be filtered with Gaussian before downscaling.- No effect for upscaling. Default: False+ input: The image tensor to be scale with shape of :math:`(B, C, H, W)`.+ factor: Desired scaling factor in each direction. If scalar, the value is used+ for both the x- and y-direction.+ interpolation: algorithm used for upsampling: ``'nearest'`` | ``'linear'`` | ``'bilinear'`` |+ ``'bicubic'`` | ``'trilinear'`` | ``'area'``.+ align_corners: interpolation flag.+ side: Corresponding side if ``size`` is an integer. Can be one of ``'short'``, ``'long'``, ``'vert'``,+ or ``'horz'``.+ antialias: if True, then image will be filtered with Gaussian before downscaling.+ No effect for upscaling.Returns:- torch.Tensor: The rescaled tensor with the shape as the specified size.+ The rescaled tensor with the shape as the specified size.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -622,21 +634,20 @@ class Resize(nn.Module):r"""Resize the input torch.Tensor to the given size.Args:- size (int, tuple(int, int)): Desired output size. If size is a sequence like (h, w),+ size: Desired output size. If size is a sequence like (h, w),output size will be matched to this. If size is an int, smaller edge of the image willbe matched to this number. i.e, if height > width, then image will be rescaledto (size * height / width, size)- interpolation (str): algorithm used for upsampling: 'nearest' | 'linear' | 'bilinear' |- 'bicubic' | 'trilinear' | 'area'. Default: 'bilinear'.- align_corners(bool): interpolation flag. Default: None. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail- side (str): Corresponding side if ``size`` is an integer. Can be one of ``"short"``, ``"long"``, ``"vert"``,- or ``"horz"``. Defaults to ``"short"``.- antialias (bool): if True, then image will be filtered with Gaussian before downscaling.- No effect for upscaling. Default: False+ interpolation: algorithm used for upsampling: ``'nearest'`` | ``'linear'`` | ``'bilinear'`` |+ 'bicubic' | 'trilinear' | 'area'.+ align_corners: interpolation flag.+ side: Corresponding side if ``size`` is an integer. Can be one of ``'short'``, ``'long'``, ``'vert'``,+ or ``'horz'``.+ antialias: if True, then image will be filtered with Gaussian before downscaling.+ No effect for upscaling.Returns:- torch.Tensor: The resized tensor with the shape of the given size.+ The resized tensor with the shape of the given size.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -675,28 +686,28 @@ class Affine(nn.Module):r"""Apply multiple elementary affine transforms simultaneously.Args:- angle (torch.Tensor, optional): Angle in degrees for counter-clockwise rotation around the center. The tensor+ angle: Angle in degrees for counter-clockwise rotation around the center. The tensormust have a shape of (B), where B is the batch size.- translation (torch.Tensor, optional): Amount of pixels for translation in x- and y-direction. The tensor must+ translation: Amount of pixels for translation in x- and y-direction. The tensor musthave a shape of (B, 2), where B is the batch size and the last dimension contains dx and dy.- scale_factor (torch.Tensor, optional): Factor for scaling. The tensor must have a shape of (B), where B is the+ scale_factor: Factor for scaling. The tensor must have a shape of (B), where B is thebatch size.- shear (torch.Tensor, optional): Angles in degrees for shearing in x- and y-direction around the center. The+ shear: Angles in degrees for shearing in x- and y-direction around the center. Thetensor must have a shape of (B, 2), where B is the batch size and the last dimension contains sx and sy.- center (torch.Tensor, optional): Transformation center in pixels. The tensor must have a shape of (B, 2), where+ center: Transformation center in pixels. The tensor must have a shape of (B, 2), whereB is the batch size and the last dimension contains cx and cy. Defaults to the center of image to betransformed.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Raises:RuntimeError: If not one of ``angle``, ``translation``, ``scale_factor``, or ``shear`` is set.Returns:- torch.Tensor: The transformed tensor with same shape as input.+ The transformed tensor with same shape as input.Example:>>> img = torch.rand(1, 2, 3, 5)@@ -771,17 +782,18 @@ class Rescale(nn.Module):r"""Rescale the input torch.Tensor with the given factor.Args:- factor (float, tuple(float, float)): Desired scaling factor in each direction. If scalar, the value is used+ factor: Desired scaling factor in each direction. If scalar, the value is usedfor both the x- and y-direction.- interpolation (str): Algorithm used for upsampling. Can be one of ``"nearest"``, ``"linear"``, ``"bilinear"``,- ``"bicubic"``, ``"trilinear"``, or ``"area"``. Default: ``"bilinear"``.- align_corners(bool): Interpolation flag. Default: None. See :func:`~torch.nn.functional.interpolate` for- details.- antialias (bool): if True, then image will be filtered with Gaussian before downscaling.- No effect for upscaling. Default: False+ interpolation: algorithm used for upsampling: ``'nearest'`` | ``'linear'`` | ``'bilinear'`` |+ ``'bicubic'`` | ``'trilinear'`` | ``'area'``.+ align_corners: interpolation flag.+ side: Corresponding side if ``size`` is an integer. Can be one of ``'short'``, ``'long'``, ``'vert'``,+ or ``'horz'``.+ antialias: if True, then image will be filtered with Gaussian before downscaling.+ No effect for upscaling.Returns:- torch.Tensor: The rescaled tensor with the shape according to the given factor.+ The rescaled tensor with the shape according to the given factor.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -813,19 +825,19 @@ class Rotate(nn.Module):r"""Rotate the tensor anti-clockwise about the centre.Args:- angle (torch.Tensor): The angle through which to rotate. The tensor+ angle: The angle through which to rotate. The tensormust have a shape of (B), where B is batch size.- center (torch.Tensor): The center through which to rotate. The tensor+ center: The center through which to rotate. The tensormust have a shape of (B, 2), where B is batch size and lastdimension contains cx and cy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The rotated tensor with the same shape as the input.+ The rotated tensor with the same shape as the input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -858,17 +870,17 @@ class Translate(nn.Module):r"""Translate the tensor in pixel units.Args:- translation (torch.Tensor): tensor containing the amount of pixels to+ translation: tensor containing the amount of pixels totranslate in the x and y direction. The tensor must have a shape of(B, 2), where B is batch size, last dimension contains dx dy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The translated tensor with the same shape as the input.+ The translated tensor with the same shape as the input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -899,21 +911,21 @@ class Scale(nn.Module):r"""Scale the tensor by a factor.Args:- scale_factor (torch.Tensor): The scale factor apply. The tensor+ scale_factor: The scale factor apply. The tensormust have a shape of (B) or (B, 2), where B is batch size.If (B), isotropic scaling will perform.If (B, 2), x-y-direction specific scaling will perform.- center (torch.Tensor): The center through which to scale. The tensor+ center: The center through which to scale. The tensormust have a shape of (B, 2), where B is batch size and lastdimension contains cx and cy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The scaled tensor with the same shape as the input.+ The scaled tensor with the same shape as the input.Example:>>> img = torch.rand(1, 3, 4, 4)@@ -946,18 +958,17 @@ class Shear(nn.Module):r"""Shear the tensor.Args:- tensor (torch.Tensor): The image tensor to be skewed.- shear (torch.Tensor): tensor containing the angle to shear+ shear: tensor containing the angle to shearin the x and y direction. The tensor must have a shape of(B, 2), where B is batch size, last dimension contains shx shy.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: False.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: The skewed tensor with the same shape as the input.+ The skewed tensor with the same shape as the input.Example:>>> img = torch.rand(1, 3, 4, 4)diff --git a/kornia/geometry/transform/crop/crop2d.py b/kornia/geometry/transform/crop/crop2d.pyindex 68a39ba36..bc5927c35 100644--- a/kornia/geometry/transform/crop/crop2d.py+++ b/kornia/geometry/transform/crop/crop2d.py@@ -27,18 +27,18 @@ def crop_and_resize(r"""Extract crops from 2D images (4D tensor) and resize given a bounding box.Args:- tensor (torch.Tensor): the 2D image tensor with shape (B, C, H, W).- boxes (torch.Tensor): a tensor containing the coordinates of the bounding boxes to be extracted.+ tensor: the 2D image tensor with shape (B, C, H, W).+ boxes : a tensor containing the coordinates of the bounding boxes to be extracted.The tensor must have the shape of Bx4x2, where each box is defined in the following (clockwise)order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in the x, y order.The coordinates would compose a rectangle with a shape of (N1, N2).- size (Tuple[int, int]): a tuple with the height and width that will be+ size: a tuple with the height and width that will beused to resize the extracted patches.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | 'reflection'.+ align_corners: mode for grid_generation.Returns:torch.Tensor: tensor containing the patches with shape BxCxN1xN2.@@ -97,17 +97,17 @@ def center_crop(r"""Crop the 2D images (4D tensor) from the center.Args:- tensor (torch.Tensor): the 2D image tensor with shape (B, C, H, W).- size (Tuple[int, int]): a tuple with the expected height and width+ tensor: the 2D image tensor with shape (B, C, H, W).+ size: a tuple with the expected height and widthof the output patch.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: mode for grid_generation.Returns:- torch.Tensor: the output tensor with patches.+ the output tensor with patches.Examples:>>> input = torch.tensor([[[@@ -177,18 +177,18 @@ def crop_by_boxes(in a batch must be rectangles with same width and height.Args:- tensor (torch.Tensor): the 2D image tensor with shape (B, C, H, W).- src_box (torch.Tensor): a tensor with shape (B, 4, 2) containing the coordinates of the bounding boxes+ tensor: the 2D image tensor with shape (B, C, H, W).+ src_box: a tensor with shape (B, 4, 2) containing the coordinates of the bounding boxesto be extracted. The tensor must have the shape of Bx4x2, where each box is defined in the clockwiseorder: top-left, top-right, bottom-right and bottom-left. The coordinates must be in x, y order.- dst_box (torch.Tensor): a tensor with shape (B, 4, 2) containing the coordinates of the bounding boxes+ dst_box: a tensor with shape (B, 4, 2) containing the coordinates of the bounding boxesto be placed. The tensor must have the shape of Bx4x2, where each box is defined in the clockwiseorder: top-left, top-right, bottom-right and bottom-left. The coordinates must be in x, y order.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: mode for grid_generation.Returns:torch.Tensor: the output tensor with patches.@@ -249,17 +249,17 @@ def crop_by_transform_mat("""Perform crop transform on 2D images (4D tensor) given a perspective transformation matrix.Args:- tensor (torch.Tensor): the 2D image tensor with shape (B, C, H, W).- transform (torch.Tensor): a perspective transformation matrix with shape (B, 3, 3).- out_size (Tuple[int, int]): size of the output image (height, width).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.+ tensor: the 2D image tensor with shape (B, C, H, W).+ transform: a perspective transformation matrix with shape (B, 3, 3).+ out_size: size of the output image (height, width).+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: mode for grid_generation.Returns:- torch.Tensor: the output tensor with patches.+ the output tensor with patches."""# simulate broadcastingdst_trans_src = torch.as_tensor(transform.expand(tensor.shape[0], -1, -1), device=tensor.device, dtype=tensor.dtype)diff --git a/kornia/geometry/transform/crop/crop3d.py b/kornia/geometry/transform/crop/crop3d.pyindex ad26902d2..0a6b38477 100644--- a/kornia/geometry/transform/crop/crop3d.py+++ b/kornia/geometry/transform/crop/crop3d.py@@ -26,19 +26,18 @@ def crop_and_resize3d(r"""Extract crops from 3D volumes (5D tensor) and resize them.Args:- tensor (torch.Tensor): the 3D volume tensor with shape (B, C, D, H, W).- boxes (torch.Tensor): a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxes+ tensor: the 3D volume tensor with shape (B, C, D, H, W).+ boxes: a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxesto be extracted. The tensor must have the shape of Bx8x3, where each box is defined in the clockwiseorder: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.- size (Tuple[int, int, int]): a tuple with the height and width that will be+ size: a tuple with the height and width that will beused to resize the extracted patches.- interpolation (str): Interpolation flag. Default: 'bilinear'.- align_corners (bool): mode for grid_generation. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for details.+ interpolation: Interpolation flag.+ align_corners: mode for grid_generation.Returns:- torch.Tensor: tensor containing the patches with shape (Bx)CxN1xN2xN3.+ tensor containing the patches with shape (Bx)CxN1xN2xN3.Example:>>> input = torch.arange(64, dtype=torch.float32).view(1, 1, 4, 4, 4)@@ -123,15 +122,14 @@ def center_crop3d(r"""Crop the 3D volumes (5D tensor) at the center.Args:- tensor (torch.Tensor): the 3D volume tensor with shape (B, C, D, H, W).- size (Tuple[int, int, int]): a tuple with the expected depth, height and width+ tensor: the 3D volume tensor with shape (B, C, D, H, W).+ size: a tuple with the expected depth, height and widthof the output patch.- interpolation (str): Interpolation flag. Default: 'bilinear'.- align_corners (bool): mode for grid_generation. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for details.+ interpolation: Interpolation flag.+ align_corners : mode for grid_generation.Returns:- torch.Tensor: the output tensor with patches.+ the output tensor with patches.Examples:>>> input = torch.arange(64, dtype=torch.float32).view(1, 1, 4, 4, 4)@@ -247,21 +245,20 @@ def crop_by_boxes3d(in a batch must be rectangles with same width, height and depth.Args:- tensor (torch.Tensor): the 3D volume tensor with shape (B, C, D, H, W).- src_box (torch.Tensor): a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxes+ tensor : the 3D volume tensor with shape (B, C, D, H, W).+ src_box : a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxesto be extracted. The tensor must have the shape of Bx8x3, where each box is defined in the clockwiseorder: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.- dst_box (torch.Tensor): a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxes+ dst_box: a tensor with shape (B, 8, 3) containing the coordinates of the bounding boxesto be placed. The tensor must have the shape of Bx8x3, where each box is defined in the clockwiseorder: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.- interpolation (str): Interpolation flag. Default: 'bilinear'.- align_corners (bool): mode for grid_generation. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for details.+ interpolation: Interpolation flag.+ align_corners: mode for grid_generation.Returns:- torch.Tensor: the output tensor with patches.+ the output tensor with patches.Examples:>>> input = torch.tensor([[[@@ -346,17 +343,17 @@ def crop_by_transform_mat3d("""Perform crop transform on 3D volumes (5D tensor) given a perspective transformation matrix.Args:- tensor (torch.Tensor): the 2D image tensor with shape (B, C, H, W).- transform (torch.Tensor): a perspective transformation matrix with shape (B, 4, 4).- out_size (Tuple[int, int, int]): size of the output image (depth, height, width).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ tensor: the 2D image tensor with shape (B, C, H, W).+ transform: a perspective transformation matrix with shape (B, 4, 4).+ out_size: size of the output image (depth, height, width).+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: mode for grid_generation.Returns:- torch.Tensor: the output tensor with patches.+ the output tensor with patches."""# simulate broadcastingdst_trans_src = transform.expand(tensor.shape[0], -1, -1)diff --git a/kornia/geometry/transform/elastic_transform.py b/kornia/geometry/transform/elastic_transform.pyindex e6d9f0d15..bf626e9de 100644--- a/kornia/geometry/transform/elastic_transform.py+++ b/kornia/geometry/transform/elastic_transform.py@@ -20,25 +20,27 @@ def elastic_transform2d() -> torch.Tensor:r"""Applies elastic transform of images as described in :cite:`Simard2003BestPF`.+ .. image:: _static/img/elastic_transform2d.png+Args:- image (torch.Tensor): Input image to be transformed with shape :math:`(B, C, H, W)`.- noise (torch.Tensor): Noise image used to spatially transform the input image. Same+ image: Input image to be transformed with shape :math:`(B, C, H, W)`.+ noise: Noise image used to spatially transform the input image. Sameresolution as the input image with shape :math:`(B, 2, H, W)`. The coordinates orderit is expected to be in x-y.- kernel_size (Tuple[int, int]): the size of the Gaussian kernel. Default: (63, 63).- sigma (Tuple[float, float]): The standard deviation of the Gaussian in the y and x directions,- respecitvely. Larger sigma results in smaller pixel displacements. Default: (32, 32).- alpha (Tuple[float, float]): The scaling factor that controls the intensity of the deformation- in the y and x directions, respectively. Default: 1.- align_corners (bool): Interpolation flag used by `grid_sample`. Default: False.- mode (str): Interpolation mode used by `grid_sample`. Either 'bilinear' or 'nearest'. Default: 'bilinear'.+ kernel_size: the size of the Gaussian kernel.+ sigma: The standard deviation of the Gaussian in the y and x directions,+ respecitvely. Larger sigma results in smaller pixel displacements.+ alpha : The scaling factor that controls the intensity of the deformation+ in the y and x directions, respectively.+ align_corners: Interpolation flag used by ```grid_sample```.+ mode: Interpolation mode used by ```grid_sample```. Either ``'bilinear'`` or ``'nearest'``... note:- `sigma` and `alpha` can also be a `torch.Tensor`. However, you could not torchscript+ ```sigma``` and ```alpha``` can also be a ``torch.Tensor``. However, you could not torchscriptthis function with tensor until PyTorch 1.8 is released.Returns:- torch.Tensor: the elastically transformed input image with shape :math:`(B,C,H,W)`.+ the elastically transformed input image with shape :math:`(B,C,H,W)`.Example:>>> image = torch.rand(1, 3, 5, 5)diff --git a/kornia/geometry/transform/flips.py b/kornia/geometry/transform/flips.pyindex fa76455e8..75b7f93da 100644--- a/kornia/geometry/transform/flips.py+++ b/kornia/geometry/transform/flips.py@@ -3,14 +3,15 @@ import torch.nn as nnclass Vflip(nn.Module):- r"""Vertically flip a tensor image or a batch of tensor images. Input must- be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.+ r"""Vertically flip a tensor image or a batch of tensor images.++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Returns:- torch.Tensor: The vertically flipped image tensor+ The vertically flipped image tensor.Examples:>>> vflip = Vflip()@@ -33,14 +34,15 @@ class Vflip(nn.Module):class Hflip(nn.Module):- r"""Horizontally flip a tensor image or a batch of tensor images. Input must- be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.+ r"""Horizontally flip a tensor image or a batch of tensor images.++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Returns:- torch.Tensor: The horizontally flipped image tensor+ The horizontally flipped image tensor.Examples:>>> hflip = Hflip()@@ -63,12 +65,12 @@ class Hflip(nn.Module):class Rot180(nn.Module):- r"""Rotate a tensor image or a batch of tensor images- 180 degrees. Input must be a tensor of shape (C, H, W)- or a batch of tensors :math:`(*, C, H, W)`.+ r"""Rotate a tensor image or a batch of tensor images 180 degrees.++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Examples:>>> rot180 = Rot180()@@ -91,15 +93,17 @@ class Rot180(nn.Module):def rot180(input: torch.Tensor) -> torch.Tensor:- r"""Rotate a tensor image or a batch of tensor images- 180 degrees. Input must be a tensor of shape (C, H, W)- or a batch of tensors :math:`(*, C, H, W)`.+ r"""Rotate a tensor image or a batch of tensor images 180 degrees.++ .. image:: _static/img/rot180.png++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Returns:- torch.Tensor: The rotated image tensor+ The rotated image tensor."""@@ -107,14 +111,17 @@ def rot180(input: torch.Tensor) -> torch.Tensor:def hflip(input: torch.Tensor) -> torch.Tensor:- r"""Horizontally flip a tensor image or a batch of tensor images. Input must- be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.+ r"""Horizontally flip a tensor image or a batch of tensor images.++ .. image:: _static/img/hflip.png++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Returns:- torch.Tensor: The horizontally flipped image tensor+ The horizontally flipped image tensor."""w = input.shape[-1]@@ -122,14 +129,17 @@ def hflip(input: torch.Tensor) -> torch.Tensor:def vflip(input: torch.Tensor) -> torch.Tensor:- r"""Vertically flip a tensor image or a batch of tensor images. Input must- be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.+ r"""Vertically flip a tensor image or a batch of tensor images.++ .. image:: _static/img/vflip.png++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Args:- input (torch.Tensor): input tensor+ input: input tensor.Returns:- torch.Tensor: The vertically flipped image tensor+ The vertically flipped image tensor."""diff --git a/kornia/geometry/transform/homography_warper.py b/kornia/geometry/transform/homography_warper.pyindex efac68c81..dab3d68f1 100644--- a/kornia/geometry/transform/homography_warper.py+++ b/kornia/geometry/transform/homography_warper.py@@ -28,12 +28,12 @@ def warp_grid(grid: torch.Tensor, src_homo_dst: torch.Tensor) -> torch.Tensor:Args:grid: Unwrapped grid of the shape :math:`(1, N, W, 2)`.- src_homo_dst (torch.Tensor): Homography or homographies (stacked) to+ src_homo_dst: Homography or homographies (stacked) totransform all points in the grid. Shape of the homographyhas to be :math:`(1, 3, 3)` or :math:`(N, 1, 3, 3)`.Returns:- torch.Tensor: the transformed grid of shape :math:`(N, H, W, 2)`.+ the transformed grid of shape :math:`(N, H, W, 2)`."""batch_size: int = src_homo_dst.size(0)_, height, width, _ = grid.size()@@ -52,12 +52,12 @@ def warp_grid3d(grid: torch.Tensor, src_homo_dst: torch.Tensor) -> torch.Tensor:Args:grid: Unwrapped grid of the shape :math:`(1, D, H, W, 3)`.- src_homo_dst (torch.Tensor): Homography or homographies (stacked) to+ src_homo_dst: Homography or homographies (stacked) totransform all points in the grid. Shape of the homographyhas to be :math:`(1, 4, 4)` or :math:`(N, 1, 4, 4)`.Returns:- torch.Tensor: the transformed grid of shape :math:`(N, H, W, 3)`.+ the transformed grid of shape :math:`(N, H, W, 3)`."""batch_size: int = src_homo_dst.size(0)_, depth, height, width, _ = grid.size()@@ -86,23 +86,17 @@ def homography_warp(See :class:`~kornia.geometry.warp.HomographyWarper` for details.Args:- patch_src (torch.Tensor): The image or tensor to warp. Should be from- source of shape :math:`(N, C, H, W)`.- src_homo_dst (torch.Tensor): The homography or stack of homographies- from destination to source of shape- :math:`(N, 3, 3)`.- dsize (Tuple[int, int]): The height and width of the image to warp.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail- normalized_coordinates (bool): Whether the homography assumes [-1, 1] normalized- coordinates or not.+ patch_src: The image or tensor to warp. Should be from source of shape :math:`(N, C, H, W)`.+ src_homo_dst: The homography or stack of homographies from destination to source of shape+ :math:`(N, 3, 3)`.+ dsize: The height and width of the image to warp.+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.+ normalized_coordinates: Whether the homography assumes [-1, 1] normalized coordinates or not.Return:- torch.Tensor: Patch sampled at locations from source to destination.+ Patch sampled at locations from source to destination.Example:>>> input = torch.rand(1, 3, 32, 32)@@ -136,23 +130,17 @@ def homography_warp3d(r"""Warp image patchs or tensors by normalized 3D homographies.Args:- patch_src (torch.Tensor): The image or tensor to warp. Should be from- source of shape :math:`(N, C, D, H, W)`.- src_homo_dst (torch.Tensor): The homography or stack of homographies- from destination to source of shape- :math:`(N, 4, 4)`.- dsize (Tuple[int, int, int]): The height and width of the image to warp.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for details.- normalized_coordinates (bool): Whether the homography assumes [-1, 1] normalized- coordinates or not.+ patch_src: The image or tensor to warp. Should be from source of shape :math:`(N, C, D, H, W)`.+ src_homo_dst: The homography or stack of homographies from destination to source of shape+ :math:`(N, 4, 4)`.+ dsize: The height and width of the image to warp.+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.+ normalized_coordinates: Whether the homography assumes [-1, 1] normalized coordinates or not.Return:- torch.Tensor: Patch sampled at locations from source to destination.+ Patch sampled at locations from source to destination.Example:>>> input = torch.rand(1, 3, 32, 32)@@ -185,16 +173,13 @@ class HomographyWarper(nn.Module):X_{dst} = H_{src}^{\{dst\}} * X_{src}Args:- height (int): The height of the destination tensor.- width (int): The width of the destination tensor.- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- normalized_coordinates (bool): wether to use a grid with- normalized coordinates.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail+ height: The height of the destination tensor.+ width: The width of the destination tensor.+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ normalized_coordinates: wether to use a grid with normalized coordinates.+ align_corners: interpolation flag."""_warped_grid: Optional[torch.Tensor]@@ -226,7 +211,7 @@ class HomographyWarper(nn.Module):Useful when the same homography/homographies are reused.Args:- src_homo_dst (torch.Tensor): Homography or homographies (stacked) to+ src_homo_dst: Homography or homographies (stacked) totransform all points in the grid. Shape of the homographyhas to be :math:`(1, 3, 3)` or :math:`(N, 1, 3, 3)`.The homography assumes normalized coordinates [-1, 1] if@@ -238,14 +223,13 @@ class HomographyWarper(nn.Module):r"""Warp a tensor from source into reference frame.Args:- patch_src (torch.Tensor): The tensor to warp.- src_homo_dst (torch.Tensor, optional): The homography or stack of+ patch_src: The tensor to warp.+ src_homo_dst: The homography or stack ofhomographies from destination to source. The homography assumesnormalized coordinates [-1, 1] if normalized_coordinates is True.- Default: None.Return:- torch.Tensor: Patch sampled at locations from source to destination.+ Patch sampled at locations from source to destination.Shape:- Input: :math:`(N, C, H, W)` and :math:`(N, 3, 3)`@@ -309,12 +293,12 @@ def normal_transform_pixel(r"""Compute the normalization matrix from image size in pixels to [-1, 1].Args:- height (int): image height.- width (int): image width.- eps (float): epsilon to prevent divide-by-zero errors+ height image height.+ width: image width.+ eps: epsilon to prevent divide-by-zero errorsReturns:- torch.Tensor: normalized transform with shape :math:`(1, 3, 3)`.+ normalized transform with shape :math:`(1, 3, 3)`."""tr_mat = torch.tensor([[1.0, 0.0, -1.0], [0.0, 1.0, -1.0], [0.0, 0.0, 1.0]], device=device, dtype=dtype) # 3x3@@ -339,13 +323,13 @@ def normal_transform_pixel3d(r"""Compute the normalization matrix from image size in pixels to [-1, 1].Args:- depth (int): image depth.- height (int): image height.- width (int): image width.- eps (float): epsilon to prevent divide-by-zero errors+ depth: image depth.+ height: image height.+ width: image width.+ eps: epsilon to prevent divide-by-zero errorsReturns:- Tensor: normalized transform with shape :math:`(1, 4, 4)`.+ normalized transform with shape :math:`(1, 4, 4)`."""tr_mat = torch.tensor([[1.0, 0.0, 0.0, -1.0], [0.0, 1.0, 0.0, -1.0], [0.0, 0.0, 1.0, -1.0], [0.0, 0.0, 0.0, 1.0]],@@ -371,13 +355,13 @@ def normalize_homography(r"""Normalize a given homography in pixels to [-1, 1].Args:- dst_pix_trans_src_pix (torch.Tensor): homography/ies from source to destination to be+ dst_pix_trans_src_pix: homography/ies from source to destination to benormalized. :math:`(B, 3, 3)`- dsize_src (tuple): size of the source image (height, width).- dsize_dst (tuple): size of the destination image (height, width).+ dsize_src: size of the source image (height, width).+ dsize_dst: size of the destination image (height, width).Returns:- torch.Tensor: the normalized homography of shape :math:`(B, 3, 3)`.+ the normalized homography of shape :math:`(B, 3, 3)`."""check_is_tensor(dst_pix_trans_src_pix)@@ -407,13 +391,13 @@ def denormalize_homography(r"""De-normalize a given homography in pixels from [-1, 1] to actual height and width.Args:- dst_pix_trans_src_pix (torch.Tensor): homography/ies from source to destination to be+ dst_pix_trans_src_pix: homography/ies from source to destination to bedenormalized. :math:`(B, 3, 3)`- dsize_src (tuple): size of the source image (height, width).- dsize_dst (tuple): size of the destination image (height, width).+ dsize_src: size of the source image (height, width).+ dsize_dst: size of the destination image (height, width).Returns:- torch.Tensor: the denormalized homography of shape :math:`(B, 3, 3)`.+ the denormalized homography of shape :math:`(B, 3, 3)`."""check_is_tensor(dst_pix_trans_src_pix)@@ -442,13 +426,13 @@ def normalize_homography3d(r"""Normalize a given homography in pixels to [-1, 1].Args:- dst_pix_trans_src_pix (torch.Tensor): homography/ies from source to destination to be+ dst_pix_trans_src_pix: homography/ies from source to destination to benormalized. :math:`(B, 4, 4)`- dsize_src (tuple): size of the source image (depth, height, width).- dsize_src (tuple): size of the destination image (depth, height, width).+ dsize_src: size of the source image (depth, height, width).+ dsize_src: size of the destination image (depth, height, width).Returns:- Tensor: the normalized homography.+ the normalized homography.Shape:Output: :math:`(B, 4, 4)`diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.pyindex 1427eb4bf..2727242a2 100644--- a/kornia/geometry/transform/imgwarp.py+++ b/kornia/geometry/transform/imgwarp.py@@ -41,6 +41,8 @@ def warp_perspective() -> torch.Tensor:r"""Applies a perspective transformation to an image.+ .. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/warp_perspective_10_2.png+The function warp_perspective transforms the source image usingthe specified matrix:@@ -51,17 +53,15 @@ def warp_perspective(\right )Args:- src (torch.Tensor): input image with shape :math:`(B, C, H, W)`.- M (torch.Tensor): transformation matrix with shape :math:`(B, 3, 3)`.- dsize (tuple): size of the output image (height, width).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool, optional): interpolation flag. Default: None.+ src: input image with shape :math:`(B, C, H, W)`.+ M: transformation matrix with shape :math:`(B, 3, 3)`.+ dsize: size of the output image (height, width).+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners(bool, optional): interpolation flag.Returns:- torch.Tensor: the warped input image :math:`(B, C, H, W)`.+ the warped input image :math:`(B, C, H, W)`.Example:>>> img = torch.rand(1, 4, 5, 6)@@ -74,8 +74,8 @@ def warp_perspective(This function is often used in conjuntion with :func:`get_perspective_transform`... note::- See a working example `here <https://kornia.readthedocs.io/en/latest/- tutorials/warp_perspective.html>`_.+ See a working example `here <https://kornia-tutorials.readthedocs.io/en/+ latest/warp_perspective.html>`_."""if not isinstance(src, torch.Tensor):raise TypeError("Input src type is not a torch.Tensor. Got {}".format(type(src)))@@ -127,6 +127,8 @@ def warp_affine() -> torch.Tensor:r"""Applies an affine transformation to a tensor.+ .. image:: _static/img/warp_affine.png+The function warp_affine transforms the source tensor usingthe specified matrix:@@ -135,17 +137,15 @@ def warp_affine(M_{21} x + M_{22} y + M_{23} \right )Args:- src (torch.Tensor): input tensor of shape :math:`(B, C, H, W)`.- M (torch.Tensor): affine transformation of shape :math:`(B, 2, 3)`.- dsize (Tuple[int, int]): size of the output image (height, width).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.+ src: input tensor of shape :math:`(B, C, H, W)`.+ M: affine transformation of shape :math:`(B, 2, 3)`.+ dsize: size of the output image (height, width).+ mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.+ padding_mode (str): padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners : mode for grid_generation.Returns:- torch.Tensor: the warped tensor with shape :math:`(B, C, H, W)`.+ the warped tensor with shape :math:`(B, C, H, W)`.Example:>>> img = torch.rand(1, 4, 5, 6)@@ -226,12 +226,12 @@ def get_perspective_transform(src, dst):dst(i) = (x_{i}^{'},y_{i}^{'}), src(i) = (x_{i}, y_{i}), i = 0,1,2,3Args:- src (torch.Tensor): coordinates of quadrangle vertices in the source image with shape :math:`(B, 4, 2)`.- dst (torch.Tensor): coordinates of the corresponding quadrangle vertices in+ src: coordinates of quadrangle vertices in the source image with shape :math:`(B, 4, 2)`.+ dst: coordinates of the corresponding quadrangle vertices inthe destination image with shape :math:`(B, 4, 2)`.Returns:- torch.Tensor: the perspective transformation with shape :math:`(B, 3, 3)`.+ the perspective transformation with shape :math:`(B, 3, 3)`... note::This function is often used in conjuntion with :func:`warp_perspective`.@@ -308,11 +308,12 @@ def _build_perspective_param(p: torch.Tensor, q: torch.Tensor, axis: str) -> tordef angle_to_rotation_matrix(angle: torch.Tensor) -> torch.Tensor:r"""Create a rotation matrix out of angles in degrees.+Args:- angle: (torch.Tensor): tensor of angles in degrees, any shape.+ angle: tensor of angles in degrees, any shape.Returns:- torch.Tensor: tensor of *x2x2 rotation matrices.+ tensor of *x2x2 rotation matrices.Shape:- Input: :math:`(*)`@@ -351,14 +352,14 @@ def get_rotation_matrix2d(center: torch.Tensor, angle: torch.Tensor, scale: torcIf this is not the target, adjust the shift.Args:- center (torch.Tensor): center of the rotation in the source image with shape :math:`(B, 2)`.- angle (torch.Tensor): rotation angle in degrees. Positive values mean+ center: center of the rotation in the source image with shape :math:`(B, 2)`.+ angle: rotation angle in degrees. Positive values meancounter-clockwise rotation (the coordinate origin is assumed tobe the top-left corner) with shape :math:`(B)`.- scale (torch.Tensor): scale factor for x, y scaling with shape :math:`(B, 2)`.+ scale: scale factor for x, y scaling with shape :math:`(B, 2)`.Returns:- torch.Tensor: the affine matrix of 2D rotation with shape :math:`(B, 2, 3)`.+ the affine matrix of 2D rotation with shape :math:`(B, 2, 3)`.Example:>>> center = torch.zeros(1, 2)@@ -442,28 +443,30 @@ def remap() -> torch.Tensor:r"""Applies a generic geometrical transformation to a tensor.+ .. image:: _static/img/remap.png+The function remap transforms the source tensor using the specified map:.. math::\text{dst}(x, y) = \text{src}(map_x(x, y), map_y(x, y))Args:- tensor (torch.Tensor): the tensor to remap with shape (B, D, H, W).+ tensor: the tensor to remap with shape (B, D, H, W).Where D is the number of channels.- map_x (torch.Tensor): the flow in the x-direction in pixel coordinates.+ map_x: the flow in the x-direction in pixel coordinates.The tensor must be in the shape of (B, H, W).- map_y (torch.Tensor): the flow in the y-direction in pixel coordinates.+ map_y: the flow in the y-direction in pixel coordinates.The tensor must be in the shape of (B, H, W).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool, optional): mode for grid_generation. Default: None.- normalized_coordinates (bool): whether the input coordinates are- normalised in the range of [-1, 1]. Default: False+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: mode for grid_generation.+ normalized_coordinates: whether the input coordinates are+ normalised in the range of [-1, 1].Returns:- torch.Tensor: the warped tensor with same shape as the input grid maps.+ the warped tensor with same shape as the input grid maps.Example:>>> from kornia.utils import create_meshgrid@@ -523,11 +526,11 @@ def invert_affine_transform(matrix: torch.Tensor) -> torch.Tensor:The result is also a 2Γ3 matrix of the same type as M.Args:- matrix (torch.Tensor): original affine transform. The tensor must be+ matrix: original affine transform. The tensor must bein the shape of :math:`(B, 2, 3)`.Return:- torch.Tensor: the reverse affine transform with shape :math:`(B, 2, 3)`.+ the reverse affine transform with shape :math:`(B, 2, 3)`... note::This function is often used in conjuntion with :func:`warp_affine`.@@ -555,15 +558,15 @@ def get_affine_matrix2d(r"""Composes affine matrix from the components.Args:- translations (torch.Tensor): tensor containing the translation vector with shape :math:`(B, 2)`.- center (torch.Tensor): tensor containing the center vector with shape :math:`(B, 2)`.- scale (torch.Tensor): tensor containing the scale factor with shape :math:`(B, 2)`.- angle (torch.Tensor): tensor of angles in degrees :math:`(B)`.- sx (torch.Tensor, optional): tensor containing the shear factor in the x-direction with shape :math:`(B)`.- sy (torch.Tensor, optional): tensor containing the shear factor in the y-direction with shape :math:`(B)`.+ translations: tensor containing the translation vector with shape :math:`(B, 2)`.+ center: tensor containing the center vector with shape :math:`(B, 2)`.+ scale: tensor containing the scale factor with shape :math:`(B, 2)`.+ angle: tensor of angles in degrees :math:`(B)`.+ sx: tensor containing the shear factor in the x-direction with shape :math:`(B)`.+ sy: tensor containing the shear factor in the y-direction with shape :math:`(B)`.Returns:- torch.Tensor: the affine transformation matrix :math:`(B, 3, 3)`.+ the affine transformation matrix :math:`(B, 3, 3)`... note::This function is often used in conjuntion with :func:`warp_affine`, :func:`warp_perspective`.@@ -593,12 +596,12 @@ def get_shear_matrix2d(center: torch.Tensor, sx: Optional[torch.Tensor] = None,\end{bmatrix}Args:- center (torch.Tensor): shearing center coordinates of (x, y).- sx (torch.Tensor, optional): shearing degree along x axis.- sy (torch.Tensor, optional): shearing degree along y axis.+ center: shearing center coordinates of (x, y).+ sx: shearing degree along x axis.+ sy: shearing degree along y axis.Returns:- torch.Tensor: params to be passed to the affine transformation with shape :math:`(B, 3, 3)`.+ params to be passed to the affine transformation with shape :math:`(B, 3, 3)`.Examples:>>> rng = torch.manual_seed(0)@@ -654,21 +657,21 @@ def get_affine_matrix3d(r"""Composes 3d affine matrix from the components.Args:- translations (torch.Tensor): tensor containing the translation vector (dx,dy,dz) with shape :math:`(B, 3)`.- center (torch.Tensor): tensor containing the center vector (x,y,z) with shape :math:`(B, 3)`.- scale (torch.Tensor): tensor containing the scale factor with shape :math:`(B)`.- angle: (torch.Tensor): angle axis vector containing the rotation angles in degrees in the form+ translations: tensor containing the translation vector (dx,dy,dz) with shape :math:`(B, 3)`.+ center: tensor containing the center vector (x,y,z) with shape :math:`(B, 3)`.+ scale: tensor containing the scale factor with shape :math:`(B)`.+ angle: angle axis vector containing the rotation angles in degrees in the formof (rx, ry, rz) with shape :math:`(B, 3)`. Internally it calls Rodrigues to computethe rotation matrix from axis-angle.- sxy (torch.Tensor, optional): tensor containing the shear factor in the xy-direction with shape :math:`(B)`.- sxz (torch.Tensor, optional): tensor containing the shear factor in the xz-direction with shape :math:`(B)`.- syx (torch.Tensor, optional): tensor containing the shear factor in the yx-direction with shape :math:`(B)`.- syz (torch.Tensor, optional): tensor containing the shear factor in the yz-direction with shape :math:`(B)`.- szx (torch.Tensor, optional): tensor containing the shear factor in the zx-direction with shape :math:`(B)`.- szy (torch.Tensor, optional): tensor containing the shear factor in the zy-direction with shape :math:`(B)`.+ sxy: tensor containing the shear factor in the xy-direction with shape :math:`(B)`.+ sxz: tensor containing the shear factor in the xz-direction with shape :math:`(B)`.+ syx: tensor containing the shear factor in the yx-direction with shape :math:`(B)`.+ syz: tensor containing the shear factor in the yz-direction with shape :math:`(B)`.+ szx: tensor containing the shear factor in the zx-direction with shape :math:`(B)`.+ szy: tensor containing the shear factor in the zy-direction with shape :math:`(B)`.Returns:- torch.Tensor: the 3d affine transformation matrix :math:`(B, 3, 3)`.+ the 3d affine transformation matrix :math:`(B, 3, 3)`... note::This function is often used in conjuntion with :func:`warp_perspective`.@@ -715,16 +718,16 @@ def get_shear_matrix3d(t = S_{xz}S_{zx} + (S_{xz}S_{yx} + S_{yz})S_{zy} + 1Params:- center (torch.Tensor): shearing center coordinates of (x, y, z).- sxy (torch.Tensor, optional): shearing degree along x axis, towards y plane.- sxz (torch.Tensor, optional): shearing degree along x axis, towards z plane.- syx (torch.Tensor, optional): shearing degree along y axis, towards x plane.- syz (torch.Tensor, optional): shearing degree along y axis, towards z plane.- szx (torch.Tensor, optional): shearing degree along z axis, towards x plane.- szy (torch.Tensor, optional): shearing degree along z axis, towards y plane.+ center: shearing center coordinates of (x, y, z).+ sxy: shearing degree along x axis, towards y plane.+ sxz: shearing degree along x axis, towards z plane.+ syx: shearing degree along y axis, towards x plane.+ syz: shearing degree along y axis, towards z plane.+ szx: shearing degree along z axis, towards x plane.+ szy: shearing degree along z axis, towards y plane.Returns:- torch.Tensor: params to be passed to the affine transformation.+ params to be passed to the affine transformation.Examples:>>> rng = torch.manual_seed(0)diff --git a/kornia/geometry/transform/projwarp.py b/kornia/geometry/transform/projwarp.pyindex 3601b508a..d92cc51f2 100644--- a/kornia/geometry/transform/projwarp.py+++ b/kornia/geometry/transform/projwarp.py@@ -33,14 +33,14 @@ def warp_affine3d(This API signature it is experimental and might suffer some changes in the future.Args:- src (torch.Tensor): input tensor of shape :math:`(B, C, D, H, W)`.- M (torch.Tensor): projective transformation matrix of shape :math:`(B, 3, 4)`.- dsize (Tuple[int, int, int]): size of the output image (depth, height, width).- mode (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- padding_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners (bool): mode for grid_generation. Default: True.+ src : input tensor of shape :math:`(B, C, D, H, W)`.+ M: projective transformation matrix of shape :math:`(B, 3, 4)`.+ dsize: size of the output image (depth, height, width).+ mode: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ padding_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners : mode for grid_generation.Returns:torch.Tensor: the warped 3d tensor with shape :math:`(B, C, D, H, W)`.@@ -92,11 +92,11 @@ def projection_from_Rt(rmat: torch.Tensor, tvec: torch.Tensor) -> torch.Tensor:Concatenates the batch of rotations and translations such that :math:`P = [R | t]`.Args:- rmat (torch.Tensor): the rotation matrix with shape :math:`(*, 3, 3)`.- tvec (torch.Tensor): the translation vector with shape :math:`(*, 3, 1)`.+ rmat: the rotation matrix with shape :math:`(*, 3, 3)`.+ tvec: the translation vector with shape :math:`(*, 3, 1)`.Returns:- torch.Tensor: the projection matrix with shape :math:`(*, 3, 4)`.+ the projection matrix with shape :math:`(*, 3, 4)`."""assert len(rmat.shape) >= 2 and rmat.shape[-2:] == (3, 3), rmat.shape@@ -114,14 +114,14 @@ def get_projective_transform(center: torch.Tensor, angles: torch.Tensor, scales:The function computes the projection matrix given the center and angles per axis.Args:- center (torch.Tensor): center of the rotation (x,y,z) in the source with shape :math:`(B, 3)`.- angles (torch.Tensor): angle axis vector containing the rotation angles in degrees in the form+ center: center of the rotation (x,y,z) in the source with shape :math:`(B, 3)`.+ angles: angle axis vector containing the rotation angles in degrees in the formof (rx, ry, rz) with shape :math:`(B, 3)`. Internally it calls Rodrigues to computethe rotation matrix from axis-angle.- scales (torch.Tensor): scale factor for x-y-z-directions with shape :math:`(B, 3)`.+ scales: scale factor for x-y-z-directions with shape :math:`(B, 3)`.Returns:- torch.Tensor: the projection matrix of 3D rotation with shape :math:`(B, 3, 4)`.+ the projection matrix of 3D rotation with shape :math:`(B, 3, 4)`... note::This function is often used in conjuntion with :func:`warp_affine3d`.@@ -214,12 +214,12 @@ def get_perspective_transform3d(src: torch.Tensor, dst: torch.Tensor) -> torch.T\end{pmatrix}Args:- src (torch.Tensor): coordinates of quadrangle vertices in the source image with shape :math:`(B, 8, 3)`.- dst (torch.Tensor): coordinates of the corresponding quadrangle vertices in+ src: coordinates of quadrangle vertices in the source image with shape :math:`(B, 8, 3)`.+ dst: coordinates of the corresponding quadrangle vertices inthe destination image with shape :math:`(B, 8, 3)`.Returns:- torch.Tensor: the perspective transformation with shape :math:`(B, 4, 4)`.+ the perspective transformation with shape :math:`(B, 4, 4)`... note::This function is often used in conjuntion with :func:`warp_perspective3d`.@@ -388,17 +388,17 @@ def warp_perspective3d(\right )Args:- src (torch.Tensor): input image with shape :math:`(B, C, D, H, W)`.- M (torch.Tensor): transformation matrix with shape :math:`(B, 4, 4)`.- dsize (tuple): size of the output image (height, width).- flags (str): interpolation mode to calculate output values- 'bilinear' | 'nearest'. Default: 'bilinear'.- border_mode (str): padding mode for outside grid values- 'zeros' | 'border' | 'reflection'. Default: 'zeros'.- align_corners(bool): interpolation flag. Default: False.+ src: input image with shape :math:`(B, C, D, H, W)`.+ M: transformation matrix with shape :math:`(B, 4, 4)`.+ dsize: size of the output image (height, width).+ flags: interpolation mode to calculate output values+ ``'bilinear'`` | ``'nearest'``.+ border_mode: padding mode for outside grid values+ ``'zeros'`` | ``'border'`` | ``'reflection'``.+ align_corners: interpolation flag.Returns:- torch.Tensor: the warped input image :math:`(B, C, D, H, W)`.+ the warped input image :math:`(B, C, D, H, W)`... note::This function is often used in conjuntion with :func:`get_perspective_transform3d`.diff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.pyindex 4b1b857c5..851751db6 100644--- a/kornia/geometry/transform/pyramid.py+++ b/kornia/geometry/transform/pyramid.py@@ -33,14 +33,13 @@ class PyrDown(nn.Module):r"""Blurs a tensor and downsamples it.Args:- border_type (str): the padding mode to be applied before convolving.+ border_type: the padding mode to be applied before convolving.The expected modes are: ``'constant'``, ``'reflect'``,- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail+ ``'replicate'`` or ``'circular'``.+ align_corners: interpolation flag.Return:- torch.Tensor: the downsampled tensor.+ the downsampled tensor.Shape:- Input: :math:`(B, C, H, W)`@@ -64,14 +63,13 @@ class PyrUp(nn.Module):r"""Upsamples a tensor and then blurs it.Args:- borde_type (str): the padding mode to be applied before convolving.+ borde_type: the padding mode to be applied before convolving.The expected modes are: ``'constant'``, ``'reflect'``,- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail+ ``'replicate'`` or ``'circular'``.+ align_corners: interpolation flag.Return:- torch.Tensor: the upsampled tensor.+ the upsampled tensor.Shape:- Input: :math:`(B, C, H, W)`@@ -92,16 +90,17 @@ class PyrUp(nn.Module):class ScalePyramid(nn.Module):- r"""Creates an scale pyramid of image, usually used for local feature- detection. Images are consequently smoothed with Gaussian blur and- downscaled.- Arguments:- n_levels (int): number of the levels in octave.- init_sigma (float): initial blur level.- min_size (int): the minimum size of the octave in pixels. Default is 5- double_image (bool): add 2x upscaled image as 1st level of pyramid. OpenCV SIFT does this. Default is False+ r"""Creates an scale pyramid of image, usually used for local feature detection.++ Images are consequently smoothed with Gaussian blur and downscaled.++ Args:+ n_levels: number of the levels in octave.+ init_sigma: initial blur level.+ min_size: the minimum size of the octave in pixels.+ double_image: add 2x upscaled image as 1st level of pyramid. OpenCV SIFT does this.+Returns:- Tuple(List(Tensors), List(Tensors), List(Tensors)):1st output: images2nd output: sigmas (coefficients for scale conversion)3rd output: pixelDists (coefficients for coordinate conversion)@@ -112,7 +111,7 @@ class ScalePyramid(nn.Module):- Output 2nd: :math:`[(B, NL), (B, NL), (B, NL), ...]`- Output 3rd: :math:`[(B, NL), (B, NL), (B, NL), ...]`- Examples::+ Examples:>>> input = torch.rand(2, 4, 100, 100)>>> sp, sigmas, pds = ScalePyramid(3, 15)(input)"""@@ -230,16 +229,17 @@ class ScalePyramid(nn.Module):def pyrdown(input: torch.Tensor, border_type: str = 'reflect', align_corners: bool = False) -> torch.Tensor:r"""Blurs a tensor and downsamples it.+ .. image:: _static/img/pyrdown.png+Args:- input (tensor): the tensor to be downsampled.- border_type (str): the padding mode to be applied before convolving.+ input: the tensor to be downsampled.+ border_type: the padding mode to be applied before convolving.The expected modes are: ``'constant'``, ``'reflect'``,- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail.+ ``'replicate'`` or ``'circular'``.+ align_corners: interpolation flag.Return:- torch.Tensor: the downsampled tensor.+ the downsampled tensor.Examples:>>> input = torch.arange(16, dtype=torch.float32).reshape(1, 1, 4, 4)@@ -264,16 +264,16 @@ def pyrdown(input: torch.Tensor, border_type: str = 'reflect', align_corners: bodef pyrup(input: torch.Tensor, border_type: str = 'reflect', align_corners: bool = False) -> torch.Tensor:r"""Upsamples a tensor and then blurs it.+ .. image:: _static/img/pyrup.png+Args:- input (tensor): the tensor to be downsampled.- border_type (str): the padding mode to be applied before convolving.- The expected modes are: ``'constant'``, ``'reflect'``,- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.- align_corners(bool): interpolation flag. Default: False. See- https://pytorch.org/docs/stable/nn.functional.html#torch.nn.functional.interpolate for detail.+ input: the tensor to be downsampled.+ border_type: the padding mode to be applied before convolving.+ The expected modes are: ``'constant'``, ``'reflect'``, ``'replicate'`` or ``'circular'``.+ align_corners: interpolation flag.Return:- torch.Tensor: the downsampled tensor.+ the downsampled tensor.Examples:>>> input = torch.arange(4, dtype=torch.float32).reshape(1, 1, 2, 2)@@ -302,17 +302,19 @@ def build_pyramid() -> List[torch.Tensor]:r"""Constructs the Gaussian pyramid for an image.+ .. image:: _static/img/build_pyramid.png+The function constructs a vector of images and builds the Gaussian pyramidby recursively applying pyrDown to the previously built pyramid layers.Args:- input (torch.Tensor): the tensor to be used to construct the pyramid.- max_level (int): 0-based index of the last (the smallest) pyramid layer.+ input : the tensor to be used to construct the pyramid.+ max_level: 0-based index of the last (the smallest) pyramid layer.It must be non-negative.- border_type (str): the padding mode to be applied before convolving.+ border_type: the padding mode to be applied before convolving.The expected modes are: ``'constant'``, ``'reflect'``,- ``'replicate'`` or ``'circular'``. Default: ``'reflect'``.- align_corners(bool): interpolation flag. Default: False. See+ ``'replicate'`` or ``'circular'``.+ align_corners: interpolation flag.Shape:- Input: :math:`(B, C, H, W)`diff --git a/kornia/geometry/transform/thin_plate_spline.py b/kornia/geometry/transform/thin_plate_spline.pyindex 2146e336e..92a7245d8 100644--- a/kornia/geometry/transform/thin_plate_spline.py+++ b/kornia/geometry/transform/thin_plate_spline.py@@ -37,11 +37,11 @@ def get_tps_transform(points_src: torch.Tensor, points_dst: torch.Tensor) -> Tuptensor of target :math:`(x, y)` points :math:`(B, N, 2)`.Args:- points_src (torch.Tensor): batch of source points :math:`(B, N, 2)` as :math:`(x, y)` coordinate vectors.- points_dst (torch.Tensor): batch of target points :math:`(B, N, 2)` as :math:`(x, y)` coordinate vectors.+ points_src: batch of source points :math:`(B, N, 2)` as :math:`(x, y)` coordinate vectors.+ points_dst: batch of target points :math:`(B, N, 2)` as :math:`(x, y)` coordinate vectors.Returns:- Tuple[torch.Tensor, torch.Tensor]: :math:`(B, N, 2)` tensor of kernel weights and :math:`(B, 3, 2)`+ :math:`(B, N, 2)` tensor of kernel weights and :math:`(B, 3, 2)`tensor of affine weights. The last dimension contains the x-transform and y-transform weightsas seperate columns.@@ -101,13 +101,13 @@ def warp_points_tps(weights for the x-transform and tensor[..., 1] the weights for the y-transform.Args:- points_src (torch.Tensor): tensor of source points :math:`(B, N, 2)`.- kernel_centers (torch.Tensor): tensor of kernel center points :math:`(B, K, 2)`.- kernel_weights (torch.Tensor): tensor of kernl weights :math:`(B, K, 2)`.- affine_weights (torch.Tensor): tensor of affine weights :math:`(B, 3, 2)`.+ points_src: tensor of source points :math:`(B, N, 2)`.+ kernel_centers: tensor of kernel center points :math:`(B, K, 2)`.+ kernel_weights: tensor of kernl weights :math:`(B, K, 2)`.+ affine_weights: tensor of affine weights :math:`(B, 3, 2)`.Returns:- torch.Tensor: The :math:`(B, N, 2)` tensor of warped source points, from applying the TPS transform.+ The :math:`(B, N, 2)` tensor of warped source points, from applying the TPS transform.Example:>>> points_src = torch.rand(1, 5, 2)@@ -166,6 +166,8 @@ def warp_image_tps(r"""Warp an image tensor according to the thin plate spline transform defined by kernel centers,kernel weights, and affine weights.+ .. image:: _static/img/warp_image_tps.png+The transform is applied to each pixel coordinate in the output image to obtain a point in the inputimage for interpolation of the output pixel. So the TPS parameters should correspond to a warp fromoutput space to input space.@@ -174,14 +176,14 @@ def warp_image_tps(are the same as in `warp_points_tps`.Args:- image (torch.Tensor): input image tensor :math:`(B, C, H, W)`.- kernel_centers (torch.Tensor): kernel center points :math:`(B, K, 2)`.- kernel_weights (torch.Tensor): tensor of kernl weights :math:`(B, K, 2)`.- affine_weights (torch.Tensor): tensor of affine weights :math:`(B, 3, 2)`.- align_corners (bool): interpolation flag used by `grid_sample`. Default: False.+ image: input image tensor :math:`(B, C, H, W)`.+ kernel_centers: kernel center points :math:`(B, K, 2)`.+ kernel_weights: tensor of kernl weights :math:`(B, K, 2)`.+ affine_weights: tensor of affine weights :math:`(B, 3, 2)`.+ align_corners: interpolation flag used by `grid_sample`.Returns:- torch.Tensor: warped image tensor :math:`(B, C, H, W)`.+ warped image tensor :math:`(B, C, H, W)`.Example:>>> points_src = torch.rand(1, 5, 2)