imwip.matrices
Image warping is linear in terms of the input image (even if degree 3 is used for the
splines). This means that the warp can be represented by a matrix M, such that for a
(raveled) image x, the warped image is given by M @ x, where @ is Python’s
matmul (matrix multiplication) operator. The adjoint warp is given by M.T @ x or
x @ M. This module provides functions that construct this matrix as a
scipy.sparse.coo_matrix (which can then be converted to any other matrix type).
Note
imwip.operators provides Scipy LinearOperators which are equivalent
to the matrix representation, but avoid the memory use of explicly storing the matrix.
It replaces the matrix-vector multiplication with the efficient GPU implementations of
warps and adjoint warps. If you only need matrix-vector multiplications, this will be
more efficient. Only use the matrices if you need explicit access to its coefficients.
imwip.matrices.matrices_dvf
- file
matrices_dvf.py
- brief
Functions for generating sparse matrix representations of image warps described by a dvf.
- author
Jens Renders
- imwip.matrices.matrices_dvf.warp_matrix(im_shape, u, v, w=None, degree=3)
Generates a sparse matrix representing an image warping operator described by a dvf.
- Parameters
u (
numpy.ndarray) – First component of the DVF describing the warpv (
numpy.ndarray) – Second component of the DVF describing the warpw (
numpy.ndarray, optional) – Third component of the DVF describing the warp. Leave empty for a 2D warp.degree (1 or 3, optional) – Degree of the splines used for interpolation, defaults to 3.
- Returns
A matrix representing the warping operator
- Return type
imwip.matrices.matrices_affine
- file
matrices_affine.py
- brief
Functions for generating sparse matrix representations of image warps described by an affine transformation.
- author
Jens Renders
- imwip.matrices.matrices_affine.affine_warp_matrix(im_shape, A, b, degree=3)
Generates a sparse matrix representing an image warping operator described by an affine transformation.
- Parameters
A (
numpy.ndarray) – Matrix A of the affine transformation Ax + b. It shoud be an 2x2 for 2D warp and 3x3 for a 3D warp.b (
numpy.ndarray) – Vector b of the affine transformation Ax + b. It should have length 2 for a 2D warp and length 3 for a 3D warp.degree (1 or 3, optional) – Degree of the splines used for interpolation, defaults to 3.
- Returns
A matrix representing the warping operator
- Return type