class_docstr: The registration workflow allows the user to use only one type of
  registration (such as center of mass or rigid body registration only).
  
  Alternatively, a registration can be done in a progressive manner.
  For example, using affine registration with progressive set to 'True'
  will involve center of mass, translation, rigid body and full affine
  registration. Whereas, when progressive is False the registration will
  include only center of mass and affine registration. The progressive
  registration will be slower but will improve the quality.
  
  This can be controlled by using the progressive flag (True by default).
class_docstr_tok: ["The","registration","workflow","allows","the","user","to","use","only","one","type","of","registration","(","such","as","center","of","mass","or","rigid","body","registration","only",")",".","Alternatively",",","a","registration","can","be","done","in","a","progressive","manner",".","For","example",",","using","affine","registration","with","progressive","set","to","'True'","will","involve","center","of","mass",",","translation",",","rigid","body","and","full","affine","registration",".","Whereas",",","when","progressive","is","False","the","registration","will","include","only","center","of","mass","and","affine","registration",".","The","progressive","registration","will","be","slower","but","will","improve","the","quality",".","This","can","be","controlled","by","using","the","progressive","flag","(","True","by","default",")","."]
docstr: Parameters
  ----------
  static_image_files : string
      Path to the static image file.
  
  moving_image_files : string
      Path to the moving image file.
  
  transform : string, optional
      com: center of mass, trans: translation, rigid: rigid body,
      rigid_isoscaling: rigid body + isotropic scaling, rigid_scaling:
      rigid body + scaling, affine: full affine including translation,
      rotation, shearing and scaling.
  
  nbins : int, optional
      Number of bins to discretize the joint and marginal PDF.
  
  sampling_prop : int, optional
      Number ([0-100]) of voxels for calculating the PDF.
       'None' implies all voxels.
  
  metric : string, optional
      Similarity metric for gathering mutual information).
  
  level_iters : variable int, optional
      The number of iterations at each scale of the scale space.
       `level_iters[0]` corresponds to the coarsest scale,
       `level_iters[-1]` the finest, where n is the length of the
        sequence.
  
  sigmas : variable floats, optional
      Custom smoothing parameter to build the scale space (one parameter
       for each scale).
  
  factors : variable floats, optional
      Custom scale factors to build the scale space (one factor for each
       scale).
  
  progressive : boolean, optional
      Enable/Disable the progressive registration.
  
  save_metric : boolean, optional
      If true, quality assessment metric are saved in
      'quality_metric.txt'.
  
  out_dir : string, optional
      Directory to save the transformed image and the affine matrix
       (default current directory).
  
  out_moved : string, optional
      Name for the saved transformed image.
  
  out_affine : string, optional
      Name for the saved affine matrix.
  
  out_quality : string, optional
      Name of the file containing the saved quality
       metric.
code: def run(
      self,
      static_image_files,
      moving_image_files,
      transform="affine",
      nbins=32,
      sampling_prop=None,
      metric="mi",
      level_iters=(10000, 1000, 100),
      sigmas=(3.0, 1.0, 0.0),
      factors=(4, 2, 1),
      progressive=True,
      save_metric=False,
      out_dir="",
      out_moved="moved.nii.gz",
      out_affine="affine.txt",
      out_quality="quality_metric.txt",
  ):
      """
      Parameters
      ----------
      static_image_files : string
          Path to the static image file.
  
      moving_image_files : string
          Path to the moving image file.
  
      transform : string, optional
          com: center of mass, trans: translation, rigid: rigid body,
          rigid_isoscaling: rigid body + isotropic scaling, rigid_scaling:
          rigid body + scaling, affine: full affine including translation,
          rotation, shearing and scaling.
  
      nbins : int, optional
          Number of bins to discretize the joint and marginal PDF.
  
      sampling_prop : int, optional
          Number ([0-100]) of voxels for calculating the PDF.
           'None' implies all voxels.
  
      metric : string, optional
          Similarity metric for gathering mutual information).
  
      level_iters : variable int, optional
          The number of iterations at each scale of the scale space.
           `level_iters[0]` corresponds to the coarsest scale,
           `level_iters[-1]` the finest, where n is the length of the
            sequence.
  
      sigmas : variable floats, optional
          Custom smoothing parameter to build the scale space (one parameter
           for each scale).
  
      factors : variable floats, optional
          Custom scale factors to build the scale space (one factor for each
           scale).
  
      progressive : boolean, optional
          Enable/Disable the progressive registration.
  
      save_metric : boolean, optional
          If true, quality assessment metric are saved in
          'quality_metric.txt'.
  
      out_dir : string, optional
          Directory to save the transformed image and the affine matrix
           (default current directory).
  
      out_moved : string, optional
          Name for the saved transformed image.
  
      out_affine : string, optional
          Name for the saved affine matrix.
  
      out_quality : string, optional
          Name of the file containing the saved quality
           metric.
      """
  
      io_it = self.get_io_iterator()
      transform = transform.lower()
      metric = metric.upper()
      if metric != "MI":
          raise ValueError(
              "Invalid similarity metric: Please provide a"
              "valid metric."
          )
  
      if progressive:
          pipeline_opt = {
              "com": ["center_of_mass"],
              "trans": ["center_of_mass", "translation"],
              "rigid": ["center_of_mass", "translation", "rigid"],
              "rigid_isoscaling": [
                  "center_of_mass",
                  "translation",
                  "rigid_isoscaling",
              ],
              "rigid_scaling": [
                  "center_of_mass",
                  "translation",
                  "rigid_scaling",
              ],
              "affine": [
                  "center_of_mass",
                  "translation",
                  "rigid",
                  "affine",
              ],
          }
      else:
          pipeline_opt = {
              "com": ["center_of_mass"],
              "trans": ["center_of_mass", "translation"],
              "rigid": ["center_of_mass", "rigid"],
              "rigid_isoscaling": [
                  "center_of_mass",
                  "rigid_isoscaling",
              ],
              "rigid_scaling": ["center_of_mass", "rigid_scaling"],
              "affine": ["center_of_mass", "affine"],
          }
  
      pipeline = pipeline_opt.get(transform)
  
      if pipeline is None:
          raise ValueError(
              "Invalid transformation:"
              " Please see program's help"
              " for allowed values of"
              " transformation."
          )
  
      for (
          static_img,
          mov_img,
          moved_file,
          affine_matrix_file,
          qual_val_file,
      ) in io_it:
          # Load the data from the input files and store into objects.
          static, static_grid2world = load_nifti(static_img)
          moving, moving_grid2world = load_nifti(mov_img)
  
          check_dimensions(static, moving)
  
          starting_affine = None
  
          # If only center of mass is selected do not return metric
          if pipeline == ["center_of_mass"]:
              moved_image, affine_matrix = affine_registration(
                  moving,
                  static,
                  moving_grid2world,
                  static_grid2world,
                  pipeline,
                  starting_affine,
                  metric,
                  level_iters,
                  sigmas,
                  factors,
                  nbins=nbins,
                  sampling_proportion=sampling_prop,
              )
          else:
              (
                  moved_image,
                  affine_matrix,
                  xopt,
                  fopt,
              ) = affine_registration(
                  moving,
                  static,
                  moving_grid2world,
                  static_grid2world,
                  pipeline,
                  starting_affine,
                  metric,
                  level_iters,
                  sigmas,
                  factors,
                  ret_metric=True,
                  nbins=nbins,
                  sampling_proportion=sampling_prop,
              )
  
              """
                  Saving the moved image file and the affine matrix.
                  """
              logging.info("Optimal parameters: {0}".format(str(xopt)))
              logging.info("Similarity metric: {0}".format(str(fopt)))
  
              if save_metric:
                  save_qa_metric(qual_val_file, xopt, fopt)
  
          save_nifti(moved_file, moved_image, static_grid2world)
          np.savetxt(affine_matrix_file, affine_matrix)
  
imports: import logging
  from warnings import warn
  import numpy
  import nibabel
  from os.path import join
  from dipy.utils.optpkg import optional_package
  from dipy.align.imaffine import AffineMap
  from dipy.align.imwarp import SymmetricDiffeomorphicRegistration, DiffeomorphicMap
  from dipy.align.metrics import CCMetric, SSDMetric, EMMetric
  from dipy.align.reslice import reslice
  from dipy.align import affine_registration, motion_correction
  from dipy.align.streamlinear import slr_with_qbx
  from dipy.tracking.streamline import set_number_of_points
  from dipy.align.streamwarp import bundlewarp
  from dipy.core.gradients import mask_non_weighted_bvals, gradient_table
  from dipy.io.image import save_nifti, load_nifti, save_qa_metric
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.tracking.streamline import transform_streamlines
  from dipy.workflows.workflow import Workflow
label_desc: Use image node_id 1 for calling the ImageRegistrationFlow obj's underlying member method code with example usage: obj.run(static_image_files, moving_image_files, transform, nbins, sampling_prop, metric, level_iters, sigmas, factors, progressive, save_metric, out_dir, out_moved, out_affine, out_quality) without return types