Module Documentation¶
- affine_transform.transform(input_image, linear_transformation, translation, order='linear', origin=None, output_image=None, output_image_origin=None, background_value=0.0)[source]¶
Transform an image using an affine transformation.
This function applies an affine transformation to an image, meaning, it first applies a linear transformation (a combination of rotation, scaling. etc) after which additionally a translation can be included. For the linear transformation, the origin of the coordinate system can be freely chosen. E.g. you could rotate an image of two spheres around their common center of mass instead of rotating around the image center or the original origin of the image data (“The lower left corner”).
Note
The linear transformation is required to be invertible. Other properties of the given matrix are not checked.
Furthermore, an option is available to choose how data is read from the given image, in case the affine transformation does not perfectly map pixels from the given image to the output image. This is the
order
of the interpolation.The data types of the input image can be anything that is convertible to
np.float64
. Ifnp.float64
ornumpy.float32
arrays are given as input or input and output images, no copies are created. For all other input types, anp.float64
array is generated and the output image (if given) has to be of typenp.float64
.- Parameters:
input_image (nd-array) – The data to transform
linear_transformation (matrix) – A matrix of dimension
(dim, dim)
, withdim
being the dimension of the input data.translation (vector) – The translation part of the affine transformation
order ({'linear', 'cubic'}) – The interpolation order to use for sampling the input image, default is
'linear'
origin (vector, optional) – The origin to use for the linear transformation. By default, the center of the image is chosen
output_image (nd-array, optional) – The image used for storing the results. If not set, memory will be allocated internally
output_image_origin (vector, optional) – If the (0,0,0) coordinate of the output_image should not coinside with the (0,0,0) location of the input_image, this parameter can be given. E.g. if you want to only extract a slice at [:,:,x], this argument could be set to (0,0,x)
background_value (optional) – The background value to use in case points outside the input image are sampled
- Returns:
The given
output_image
or if not given a newly created array with the results- Return type:
nd-array
- Raises:
ValueError – If the dimensions of the given inputs mismatch, or the datatypes are incompatible
LinAlgError – If the given linear transformation is singular