docstr: Convert a 4x4 matrix describing an affine transform into a
  12-sized vector of natural affine parameters: translation,
  rotation, log-scale, pre-rotation (to allow for shearing when
  combined with non-unitary scales). In case the transform has a
  negative determinant, set the `_direct` attribute to False.
docstr_tok: ["Convert","a","4x4","matrix","describing","an","affine","transform","into","a","12-sized","vector","of","natural","affine","parameters",":","translation",",","rotation",",","log-scale",",","pre-rotation","(","to","allow","for","shearing","when","combined","with","non-unitary","scales",")",".","In","case","the","transform","has","a","negative","determinant",",","set","the","`","_direct","`","attribute","to","False","."]
code: def from_matrix44(self, aff):
      """
      Convert a 4x4 matrix describing an affine transform into a
      12-sized vector of natural affine parameters: translation,
      rotation, log-scale, pre-rotation (to allow for shearing when
      combined with non-unitary scales). In case the transform has a
      negative determinant, set the `_direct` attribute to False.
      """
      vec12 = np.zeros((12,))
      vec12[0:3] = aff[:3, 3]
      # Use SVD to find orthogonal and diagonal matrices such that
      # aff[0:3,0:3] == R*S*Q
      R, s, Q = spl.svd(aff[0:3, 0:3])
      if spl.det(R) < 0:
          R = -R
          Q = -Q
      r = rotation_mat2vec(R)
      if spl.det(Q) < 0:
          Q = -Q
          self._direct = False
      q = rotation_mat2vec(Q)
      vec12[3:6] = r
      vec12[6:9] = np.log(np.maximum(s, TINY))
      vec12[9:12] = q
      self._vec12 = vec12
  
imports: import numpy
  import scipy.linalg
  from nibabel.affines import apply_affine
  from transforms3d.quaternions import mat2quat, quat2axangle
  from .transform import Transform
label_desc: Use image node_id 3 for calling the Affine obj's underlying member method code with example usage: obj.from_matrix44(aff) without return types