diff --git a/fsl/utils/transform.py b/fsl/utils/transform.py index 79ab8c41478e099a20e8c490850013e4fbbc4fbb..481ae420f238911a35a218ccb169c98e71976b95 100644 --- a/fsl/utils/transform.py +++ b/fsl/utils/transform.py @@ -22,6 +22,14 @@ spaces. The following functions are provided: axisBounds flirtMatrixToSform sformToFlirtMatrix + +And a few more functions are provided for working with vectors: + +.. autosummary:: + :nosignatures: + + veclength + normalise """ import numpy as np @@ -45,6 +53,16 @@ def concat(*xforms): return result +def veclength(vec): + """Returns the length of the given vector. """ + return np.sqrt(np.dot(vec, vec)) + + +def normalise(vec): + """Normalises the given vector to unit length. """ + return vec / veclength(vec) + + def scaleOffsetXform(scales, offsets): """Creates and returns an affine transformation matrix which encodes the specified scale(s) and offset(s).