docstr: Optimize motion parameters for the whole sequence. All the
  time frames are initially resampled according to the current
  space/time transformation, the parameters of which are further
  optimized sequentially.
docstr_tok: ["Optimize","motion","parameters","for","the","whole","sequence",".","All","the","time","frames","are","initially","resampled","according","to","the","current","space\/time","transformation",",","the","parameters","of","which","are","further","optimized","sequentially","."]
code: def estimate_motion(self):
      """
      Optimize motion parameters for the whole sequence. All the
      time frames are initially resampled according to the current
      space/time transformation, the parameters of which are further
      optimized sequentially.
      """
      for t in range(self.nscans):
          if VERBOSE:
              print("Resampling scan %d/%d" % (t + 1, self.nscans))
          self.resample(t)
  
      # Set the template as the reference scan (will be overwritten
      # if template is to be optimized)
      if not hasattr(self, "template"):
          self.mu = self.data[:, self.refscan].copy()
      for t in range(self.nscans):
          self.estimate_instant_motion(t)
          if VERBOSE:
              print(self.transforms[t])
  
imports: import os
  import warnings
  import numpy
  from nibabel import io_orientation
  from nibabel.affines import apply_affine
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ...io.nibcompat import get_header
  from ..slicetiming import timefuncs
  from ._registration import _cspline_sample3d, _cspline_sample4d, _cspline_transform
  from .affine import Affine, Rigid
  from .optimizer import configure_optimizer, use_derivatives
  from .type_check import check_type, check_type_and_shape
label_desc: Use image node_id 12 for calling the Realign4dAlgorithm obj's underlying member method code with example usage: obj.estimate_motion() without return types