docstr: Prepares the metric to compute one displacement field iteration.
  
  Pre-computes the cross-correlation factors for efficient computation
  of the gradient of the Cross Correlation w.r.t. the displacement field.
  It also pre-computes the image gradients in the physical space by
  re-orienting the gradients in the voxel space using the corresponding
  affine transformations.
docstr_tok: ["Prepares","the","metric","to","compute","one","displacement","field","iteration",".","Pre-computes","the","cross-correlation","factors","for","efficient","computation","of","the","gradient","of","the","Cross","Correlation","w.r.t",".","the","displacement","field",".","It","also","pre-computes","the","image","gradients","in","the","physical","space","by","re-orienting","the","gradients","in","the","voxel","space","using","the","corresponding","affine","transformations","."]
code: def initialize_iteration(self):
      r"""Prepares the metric to compute one displacement field iteration.
  
      Pre-computes the cross-correlation factors for efficient computation
      of the gradient of the Cross Correlation w.r.t. the displacement field.
      It also pre-computes the image gradients in the physical space by
      re-orienting the gradients in the voxel space using the corresponding
      affine transformations.
      """
      min_size = self.radius * 2 + 1
  
      def invalid_image_size(image):
          return any(size < min_size for size in image.shape)
  
      msg = (
          "Each image dimension should be superior to 2 * radius + 1 "
          f"({min_size}). Decrease CCMetric radius ({self.radius}) or "
          "increase your image size (shape=%(shape)s)."
      )
  
      if invalid_image_size(self.static_image):
          raise ValueError(
              "Static image size is too small. "
              + msg % dict(shape=self.static_image.shape)
          )
      if invalid_image_size(self.moving_image):
          raise ValueError(
              "Moving image size is too small. "
              + msg % dict(shape=self.moving_image.shape)
          )
  
      self.factors = self.precompute_factors(
          self.static_image, self.moving_image, self.radius
      )
      self.factors = np.array(self.factors)
  
      self.gradient_moving = np.empty(
          shape=self.moving_image.shape + (self.dim,), dtype=floating
      )
      for i, grad in enumerate(gradient(self.moving_image)):
          self.gradient_moving[..., i] = grad
  
      # Convert moving image's gradient field from voxel to physical space
      if self.moving_spacing is not None:
          self.gradient_moving /= self.moving_spacing
      if self.moving_direction is not None:
          self.reorient_vector_field(
              self.gradient_moving, self.moving_direction
          )
  
      self.gradient_static = np.empty(
          shape=self.static_image.shape + (self.dim,), dtype=floating
      )
      for i, grad in enumerate(gradient(self.static_image)):
          self.gradient_static[..., i] = grad
  
      # Convert moving image's gradient field from voxel to physical space
      if self.static_spacing is not None:
          self.gradient_static /= self.static_spacing
      if self.static_direction is not None:
          self.reorient_vector_field(
              self.gradient_static, self.static_direction
          )
  
imports: import abc
  import numpy
  from numpy import gradient
  from scipy import ndimage
  from dipy.align import vector_fields
  from dipy.align import sumsqdiff
  from dipy.align import crosscorr
  from dipy.align import expectmax
  from dipy.align import floating
label_desc: Use image node_id 3 for calling the CCMetric obj's underlying member method code with example usage: obj.initialize_iteration() and returns: any