docstr: Initialize an instance of the Mutual Information metric.
  
  This class implements the methods required by Optimizer to drive the
  registration process.
  
  Parameters
  ----------
  nbins : int, optional
      the number of bins to be used for computing the intensity
      histograms. The default is 32.
  sampling_proportion : None or float in interval (0, 1], optional
      There are two types of sampling: dense and sparse. Dense sampling
      uses all voxels for estimating the (joint and marginal) intensity
      histograms, while sparse sampling uses a subset of them. If
      `sampling_proportion` is None, then dense sampling is
      used. If `sampling_proportion` is a floating point value in (0,1]
      then sparse sampling is used, where `sampling_proportion`
      specifies the proportion of voxels to be used. The default is
      None.
  
  Notes
  -----
  Since we use linear interpolation, images are not, in general,
  differentiable at exact voxel coordinates, but they are differentiable
  between voxel coordinates. When using sparse sampling, selected voxels
  are slightly moved by adding a small random displacement within one
  voxel to prevent sampling points from being located exactly at voxel
  coordinates. When using dense sampling, this random displacement is
  not applied.
docstr_tok: ["Initialize","an","instance","of","the","Mutual","Information","metric",".","This","class","implements","the","methods","required","by","Optimizer","to","drive","the","registration","process",".","Parameters","--","--","--","--","--","nbins",":","int",",","optional","the","number","of","bins","to","be","used","for","computing","the","intensity","histograms",".","The","default","is","32.","sampling_proportion",":","None","or","float","in","interval","(","0",",","1","]",",","optional","There","are","two","types","of","sampling",":","dense","and","sparse",".","Dense","sampling","uses","all","voxels","for","estimating","the","(","joint","and","marginal",")","intensity","histograms",",","while","sparse","sampling","uses","a","subset","of","them",".","If","`","sampling_proportion","`","is","None",",","then","dense","sampling","is","used",".","If","`","sampling_proportion","`","is","a","floating","point","value","in","(","0,1","]","then","sparse","sampling","is","used",",","where","`","sampling_proportion","`","specifies","the","proportion","of","voxels","to","be","used",".","The","default","is","None",".","Notes","--","--","-","Since","we","use","linear","interpolation",",","images","are","not",",","in","general",",","differentiable","at","exact","voxel","coordinates",",","but","they","are","differentiable","between","voxel","coordinates",".","When","using","sparse","sampling",",","selected","voxels","are","slightly","moved","by","adding","a","small","random","displacement","within","one","voxel","to","prevent","sampling","points","from","being","located","exactly","at","voxel","coordinates",".","When","using","dense","sampling",",","this","random","displacement","is","not","applied","."]
code: def __init__(self, nbins=32, sampling_proportion=None):
      r"""Initialize an instance of the Mutual Information metric.
  
      This class implements the methods required by Optimizer to drive the
      registration process.
  
      Parameters
      ----------
      nbins : int, optional
          the number of bins to be used for computing the intensity
          histograms. The default is 32.
      sampling_proportion : None or float in interval (0, 1], optional
          There are two types of sampling: dense and sparse. Dense sampling
          uses all voxels for estimating the (joint and marginal) intensity
          histograms, while sparse sampling uses a subset of them. If
          `sampling_proportion` is None, then dense sampling is
          used. If `sampling_proportion` is a floating point value in (0,1]
          then sparse sampling is used, where `sampling_proportion`
          specifies the proportion of voxels to be used. The default is
          None.
  
      Notes
      -----
      Since we use linear interpolation, images are not, in general,
      differentiable at exact voxel coordinates, but they are differentiable
      between voxel coordinates. When using sparse sampling, selected voxels
      are slightly moved by adding a small random displacement within one
      voxel to prevent sampling points from being located exactly at voxel
      coordinates. When using dense sampling, this random displacement is
      not applied.
  
      """
      self.histogram = ParzenJointHistogram(nbins)
      self.sampling_proportion = sampling_proportion
      self.metric_val = None
      self.metric_grad = None
  
imports: from warnings import warn
  import numpy
  import numpy.linalg
  import scipy.ndimage
  from dipy.core.optimize import Optimizer
  from dipy.core.interpolation import interpolate_scalar_2d, interpolate_scalar_3d
  from dipy.align import vector_fields
  from dipy.align import VerbosityLevels
  from dipy.align.parzenhist import ParzenJointHistogram, sample_domain_regular, compute_parzen_mi
  from dipy.align.imwarp import get_direction_and_spacings, ScaleSpace
  from dipy.align.scalespace import IsotropicScaleSpace
  from dipy.utils.deprecator import deprecated_params
label_desc: Use image node_id 1 to create a new MutualInformationMetric object  with example: obj = MutualInformationMetric(nbins, sampling_proportion)