Types of homographies¶
Homographies are transformations of a Euclidean space that preserve the alignment of points. Specific cases of homographies correspond to the conservation of more properties, such as parallelism (affine transformation), shape (similar transformation) or distances (Euclidean transformation).
Homographies on a 2D Euclidean space (i.e., for 2D grayscale or multichannel images) are defined by a 3x3 matrix. All types of homographies can be defined by passing either the transformation matrix, or the parameters of the simpler transformations (rotation, scaling, …) which compose the full transformation.
The different types of homographies available in scikit-image are shown here, by increasing order of complexity (i.e. by reducing the number of constraints). While we focus here on the mathematical properties of transformations, tutorial Using geometric transformations explains how to use such transformations for various tasks such as image warping or parameter estimation.
import math import numpy as np import matplotlib.pyplot as plt from skimage import data from skimage import transform from skimage import img_as_float
Euclidean (rigid) transformation¶
A Euclidean transformation, also called rigid transformation, preserves the Euclidean distance between pairs of points. It can be described as a rotation about the origin followed by a translation.
[[ 0.96592583 -0.25881905 100. ] [ 0.25881905 0.96592583 -20. ] [ 0. 0. 1. ]]
Now let’s apply this transformation to an image. Because we are trying
to reconstruct the image after transformation, it is not useful to see
where a coordinate from the input image ends up in the output, which is
what the transform gives us. Instead, for every pixel (coordinate) in the
output image, we want to figure out where in the input image it comes from.
Therefore, we need to use the inverse of
tform, rather than
For a rotation around the center of the image, one can compose a translation to change the origin, a rotation, and finally the inverse of the first translation.
rotation = transform.EuclideanTransform(rotation=np.pi/3) shift = transform.EuclideanTransform(translation=-np.array(img.shape[:2]) / 2) # Compose transforms by multiplying their matrices matrix = np.linalg.inv(shift.params) @ rotation.params @ shift.params tform = transform.EuclideanTransform(matrix) tf_img = transform.warp(img, tform.inverse) fig, ax = plt.subplots() _ = ax.imshow(tf_img)
A similarity transformation preserves the shape of objects. It combines scaling, translation and rotation.
[[ 0.48296291 -0.12940952 100. ] [ 0.12940952 0.48296291 50. ] [ 0. 0. 1. ]]
[[ 1. -0.5 0. ] [ 0. 0.8660254 0. ] [ 0. 0. 1. ]]
Projective transformation (homographies)¶
A homography, also called projective transformation, preserves lines but not necessarily parallelism.
Using geometric transformations for composing transformations or estimating their parameters
Rescale, resize, and downscale for simple rescaling and resizing operations
skimage.transform.rotate()for rotating an image around its center
Total running time of the script: ( 0 minutes 2.152 seconds)