Homography#

class deepinv.transform.Homography(n_trans: int = 1, theta_max: float = 180.0, theta_z_max: float = 180.0, zoom_factor_min: float = 0.5, shift_max: float = 1.0, skew_max: float = 50.0, x_stretch_factor_min: float = 0.5, y_stretch_factor_min: float = 0.5, padding: str = 'reflection', interpolation: str = 'bilinear', device: str = 'cpu')[source]#

Bases: Transform

Random projective transformations (homographies).

The homography is parameterised by geometric parameters. By fixing these parameters, subgroup transformations are retrieved, see Wang et al. “Perspective-Equivariant Imaging: an Unsupervised Framework for Multispectral Pansharpening” https://arxiv.org/abs/2403.09327

For example, setting x_stretch_factor_min = y_stretch_factor_min = zoom_factor_min = 1, theta_max = theta_z_max = skew_max = 0 gives a pure translation.

Subgroup transformations include deepinv.transform.Affine, deepinv.transform.Similarity, deepinv.transform.Euclidean along with the basic deepinv.transform.Shift, deepinv.transform.Rotation and semigroup deepinv.transform.Scale.

Transformations with perspective effects (i.e. pan+tilt) are recovered by setting theta_max > 0.

Generates n_trans random transformations concatenated along the batch dimension.


Example:

Apply a random projective transformation:

>>> from deepinv.transform.projective import Homography
>>> x = torch.randn(1, 3, 16, 16) # Random 16x16 image
>>> transform = Homography(n_trans = 1)
>>> x_T = transform(x)
Parameters:
  • theta_max (float) – Maximum pan+tilt angle in degrees, defaults to 180.

  • theta_z_max (float) – Maximum 2D z-rotation angle in degrees, defaults to 180.

  • zoom_factor_min (float) – Minimum zoom factor (up to 1), defaults to 0.5.

  • shift_max (float) – Maximum shift percentage, where 1 is full shift, defaults to 1.

  • skew_max (float) – Maximum skew parameter, defaults to 50.

  • x_stretch_factor_min (float) – Min stretch factor along the x-axis (up to 1), defaults to 0.5.

  • y_stretch_factor_min (float) – Min stretch factor along the y-axis (up to 1), defaults to 0.5.

  • padding (str) – kornia padding mode, defaults to “reflection”

  • interpolation (str) – kornia or PIL interpolation mode, defaults to “bilinear”

  • device (str) – torch device, defaults to “cpu”.

  • n_trans (int) – number of transformed versions generated per input image, defaults to 1.

  • rng (torch.Generator) – random number generator, if None, use torch.Generator(), defaults to None

Examples using Homography:#

Image transforms for equivariance & augmentations

Image transforms for equivariance & augmentations

Image transformations for Equivariant Imaging

Image transformations for Equivariant Imaging