affine_transform

sunpy.image.transform.affine_transform(image, rmatrix, order=3, scale=1.0, image_center=None, recenter=False, missing=0.0, use_scipy=False)[source] [edit on github]

Rotates, shifts and scales an image using skimage.transform.warp(), or scipy.ndimage.interpolation.affine_transform() if specified. Falls back to the scipy function if scikit-image can’t be imported.

Parameters:
  • image (numpy.ndarray) – 2D Image to be rotated.
  • rmatrix (2x2) – Linear transformation rotation matrix.
  • order (int 0-5) – Interpolation order to be used. When using scikit-image this parameter is passed into skimage.transform.warp() (e.g., 3 corresponds to bi-cubic interpolation). When using scipy it is passed into scipy.ndimage.interpolation.affine_transform() where it controls the order of the spline. Default: 3
  • scale (float) – A scale factor for the image. Default is no scaling.
  • image_center (tuple) – The point in the image to rotate around (axis of rotation). Default: center of the array.
  • recenter (bool or array-like) – Move the axis of rotation to the center of the array or recenter coords. Default: True, recenter to the center of the array.
  • missing (float) – The value to replace any missing data after the transformation.
  • use_scipy (bool) – Force use of scipy.ndimage.interpolation.affine_transform(). Will set all NaNs in image to zero before doing the transform. Default: False, unless scikit-image can’t be imported
Returns:

out (New rotated, scaled and translated image.)

Notes

This algorithm uses an affine transformation as opposed to a polynomial geometrical transformation, which by default is skimage.transform.warp(). One can specify using scipy.ndimage.interpolation.affine_transform() as an alternative affine transformation. The two transformations use different algorithms and thus do not give identical output.

When using for skimage.transform.warp() with order >= 4 or using scipy.ndimage.interpolation.affine_transform() at all, NaN values will replaced with zero prior to rotation. No attempt is made to retain the NaN values.

Input arrays with integer data are cast to float64 and can be re-cast using numpy.ndarray.astype() if desired.

Although this function is analogous to the IDL’s rot() function, it does not use the same algorithm as the IDL rot() function. IDL’s rot() calls the POLY_2D method to calculate the inverse mapping of original to target pixel coordinates. This is a polynomial geometrical transformation. Then optionally it uses a bicubic convolution interpolation algorithm to map the original to target pixel values.