class_docstr: A class to represent a generic intensity-based image registration
  algorithm.
class_docstr_tok: ["A","class","to","represent","a","generic","intensity-based","image","registration","algorithm","."]
docstr:  Creates a new histogram registration object.
  
   Parameters
   ----------
   from_img : nipy-like image
     `From` image
   to_img : nipy-like image
     `To` image
   from_bins : integer
     Number of histogram bins to represent the `from` image
   to_bins : integer
     Number of histogram bins to represent the `to` image
   from_mask : array-like
     Mask to apply to the `from` image
   to_mask : array-like
     Mask to apply to the `to` image
   similarity : str or callable
     Cost-function for assessing image similarity. If a string,
     one of 'cc': correlation coefficient, 'cr': correlation
     ratio, 'crl1': L1-norm based correlation ratio, 'mi': mutual
     information, 'nmi': normalized mutual information, 'slr':
     supervised log-likelihood ratio. If a callable, it should
     take a two-dimensional array representing the image joint
     histogram as an input and return a float.
  dist: None or array-like
     Joint intensity probability distribution model for use with the
     'slr' measure. Should be of shape (from_bins, to_bins).
  interp : str
    Interpolation method.  One of 'pv': Partial volume, 'tri':
    Trilinear, 'rand': Random interpolation.  See ``joint_histogram.c``
  smooth : float
    Standard deviation in millimeters of an isotropic Gaussian
    kernel used to smooth the `To` image. If 0, no smoothing is
    applied.
   
docstr_tok: ["Creates","a","new","histogram","registration","object",".","Parameters","--","--","--","--","--","from_img",":","nipy-like","image","`","From","`","image","to_img",":","nipy-like","image","`","To","`","image","from_bins",":","integer","Number","of","histogram","bins","to","represent","the","`","from","`","image","to_bins",":","integer","Number","of","histogram","bins","to","represent","the","`","to","`","image","from_mask",":","array-like","Mask","to","apply","to","the","`","from","`","image","to_mask",":","array-like","Mask","to","apply","to","the","`","to","`","image","similarity",":","str","or","callable","Cost-function","for","assessing","image","similarity",".","If","a","string",",","one","of","'cc","'",":","correlation","coefficient",",","'cr","'",":","correlation","ratio",",","'crl1","'",":","L1-norm","based","correlation","ratio",",","'mi","'",":","mutual","information",",","'nmi","'",":","normalized","mutual","information",",","'slr","'",":","supervised","log-likelihood","ratio",".","If","a","callable",",","it","should","take","a","two-dimensional","array","representing","the","image","joint","histogram","as","an","input","and","return","a","float",".","dist",":","None","or","array-like","Joint","intensity","probability","distribution","model","for","use","with","the","'slr","'","measure",".","Should","be","of","shape","(","from_bins",",","to_bins",")",".","interp",":","str","Interpolation","method",".","One","of","'pv","'",":","Partial","volume",",","'tri","'",":","Trilinear",",","'rand","'",":","Random","interpolation",".","See","``","joint_histogram.c","``","smooth",":","float","Standard","deviation","in","millimeters","of","an","isotropic","Gaussian","kernel","used","to","smooth","the","`","To","`","image",".","If","0",",","no","smoothing","is","applied","."]
code: def __init__(
      self,
      from_img,
      to_img,
      from_bins=256,
      to_bins=None,
      from_mask=None,
      to_mask=None,
      similarity="crl1",
      interp="pv",
      smooth=0,
      renormalize=False,
      dist=None,
  ):
      """
       Creates a new histogram registration object.
  
       Parameters
       ----------
       from_img : nipy-like image
         `From` image
       to_img : nipy-like image
         `To` image
       from_bins : integer
         Number of histogram bins to represent the `from` image
       to_bins : integer
         Number of histogram bins to represent the `to` image
       from_mask : array-like
         Mask to apply to the `from` image
       to_mask : array-like
         Mask to apply to the `to` image
       similarity : str or callable
         Cost-function for assessing image similarity. If a string,
         one of 'cc': correlation coefficient, 'cr': correlation
         ratio, 'crl1': L1-norm based correlation ratio, 'mi': mutual
         information, 'nmi': normalized mutual information, 'slr':
         supervised log-likelihood ratio. If a callable, it should
         take a two-dimensional array representing the image joint
         histogram as an input and return a float.
      dist: None or array-like
         Joint intensity probability distribution model for use with the
         'slr' measure. Should be of shape (from_bins, to_bins).
      interp : str
        Interpolation method.  One of 'pv': Partial volume, 'tri':
        Trilinear, 'rand': Random interpolation.  See ``joint_histogram.c``
      smooth : float
        Standard deviation in millimeters of an isotropic Gaussian
        kernel used to smooth the `To` image. If 0, no smoothing is
        applied.
      """
      # Function assumes xyx_affine for inputs
      from_img = as_xyz_image(from_img)
      to_img = as_xyz_image(to_img)
  
      # Binning sizes
      if to_bins is None:
          to_bins = from_bins
  
      # Clamping of the `from` image. The number of bins may be
      # overridden if unnecessarily large.
      data, from_bins_adjusted = clamp(
          from_img.get_fdata(), from_bins, mask=from_mask
      )
      if similarity != "slr":
          from_bins = from_bins_adjusted
      self._from_img = make_xyz_image(
          data, xyz_affine(from_img), "scanner"
      )
      # Set field of view in the `from` image with potential
      # subsampling for faster similarity evaluation. This also sets
      # the _from_data and _vox_coords attributes
      if from_mask is None:
          self.subsample(npoints=NPOINTS)
      else:
          corner, size = smallest_bounding_box(from_mask)
          self.set_fov(corner=corner, size=size, npoints=NPOINTS)
  
      # Clamping of the `to` image including padding with -1
      self._smooth = float(smooth)
      if self._smooth < 0:
          raise ValueError(
              "smoothing kernel cannot have negative scale"
          )
      elif self._smooth > 0:
          data = smooth_image(
              to_img.get_fdata(), xyz_affine(to_img), self._smooth
          )
      else:
          data = to_img.get_fdata()
      data, to_bins_adjusted = clamp(data, to_bins, mask=to_mask)
      if similarity != "slr":
          to_bins = to_bins_adjusted
      self._to_data = -np.ones(
          np.array(to_img.shape) + 2, dtype=CLAMP_DTYPE
      )
      self._to_data[1:-1, 1:-1, 1:-1] = data
      self._to_inv_affine = inverse_affine(xyz_affine(to_img))
  
      # Joint histogram: must be double contiguous as it will be
      # passed to C routines which assume so
      self._joint_hist = np.zeros([from_bins, to_bins], dtype="double")
  
      # Set default registration parameters
      self._set_interp(interp)
      self._set_similarity(
          similarity, renormalize=renormalize, dist=dist
      )
  
imports: import numpy
  import scipy.ndimage
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ._registration import _joint_histogram
  from .affine import affine_transforms, inverse_affine, subgrid_affine
  from .chain_transform import ChainTransform
  from .optimizer import configure_optimizer
  from .similarity_measures import similarity_measures
label_desc: Use image node_id 1 to create a new HistogramRegistration object  with example: obj = HistogramRegistration(from_img, to_img, from_bins, to_bins, from_mask, to_mask, similarity, interp, smooth, renormalize, dist)