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.

Will use skimage.transform.warp unless scikit-image can’t be imported then it will use`scipy.ndimage.interpolation.affine_transform`.

Parameters
  • image (numpy.ndarray) – 2D image to be rotated.

  • rmatrix (numpy.ndarray that is 2x2) – Linear transformation rotation matrix.

  • order (int 0-5, optional) – Interpolation order to be used, defaults to 3. 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.

  • scale (float) – A scale factor for the image with the default being no scaling.

  • image_center (tuple, optional) – The point in the image to rotate around (axis of rotation). Defaults to the center of the array.

  • recenter (bool or array-like, optional) – Move the axis of rotation to the center of the array or recenter coords. Defaults to True i.e., recenter to the center of the array.

  • missing (float, optional) – The value to replace any missing data after the transformation.

  • use_scipy (bool, optional) – Force use of scipy.ndimage.interpolation.affine_transform. Will set all “NaNs” in image to zero before doing the transform. Defaults to False, unless scikit-image can’t be imported.

Returns

numpy.ndarray – 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 float 64 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.