code: def _clamp(x, y, bins):
      # Threshold
      dmaxmax = 2 ** (8 * y.dtype.itemsize - 1) - 1
      dmax = bins - 1  # default output maximum value
      if dmax > dmaxmax:
          raise ValueError("Excess number of bins")
      xmin = float(x.min())
      xmax = float(x.max())
      d = xmax - xmin
  
      """
      If the image dynamic is small, no need for compression: just
      downshift image values and re-estimate the dynamic range (hence
      xmax is translated to xmax-tth casted to the appropriate
      dtype. Otherwise, compress after downshifting image values (values
      equal to the threshold are reset to zero).
      """
      if issubclass(x.dtype.type, np.integer) and d <= dmax:
          y[:] = x - xmin
          bins = int(d) + 1
      else:
          a = dmax / d
          y[:] = np.round(a * (x - xmin))
  
      return y, bins
  
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 for calling a global function with example usage: _clamp(x, y, bins) and returns: y,  bins