class_docstr: Class to normalize patches/images to a reference or target image stain (see Note).
  
  Performs stain deconvolution of the source image using the ExtractHEStains
  class, to obtain the stain matrix and calculate the stain concentration matrix
  for the image. Then, performs the inverse Beer-Lambert transform to recreate the
  patch using the target H&E stain matrix provided. If no target stain provided, a default
  reference stain is used. Similarly, if no maximum stain concentrations are provided, a
  reference maximum stain concentrations matrix is used.
  
  Args:
      tli: transmitted light intensity. Defaults to 240.
      alpha: tolerance in percentile for the pseudo-min (alpha percentile) and
          pseudo-max (100 - alpha percentile). Defaults to 1.
      beta: absorbance threshold for transparent pixels. Defaults to 0.15.
      target_he: target stain matrix. Defaults to ((0.5626, 0.2159), (0.7201, 0.8012), (0.4062, 0.5581)).
      max_cref: reference maximum stain concentrations for Hematoxylin & Eosin (H&E).
          Defaults to [1.9705, 1.0308].
  
  Note:
      For more information refer to:
      - the original paper: Macenko et al., 2009 http://wwwx.cs.unc.edu/~mn/sites/default/files/macenko2009.pdf
      - the previous implementations:
  
          - MATLAB: https://github.com/mitkovetta/staining-normalization
          - Python: https://github.com/schaugf/HEnorm_python
docstr: Perform stain normalization.
  
  Args:
      image: uint8 RGB image/patch to be stain normalized, pixel values between 0 and 255
  
  Return:
      image_norm: stain normalized image/patch
code: def __call__(self, image: np.ndarray) -> np.ndarray:
      """Perform stain normalization.
  
      Args:
          image: uint8 RGB image/patch to be stain normalized, pixel values between 0 and 255
  
      Return:
          image_norm: stain normalized image/patch
      """
      # check image type and values
      if not isinstance(image, np.ndarray):
          raise TypeError("Image must be of type numpy.ndarray.")
      if image.min() < 0:
          raise ValueError("Image should not have negative values.")
      if image.max() > 255:
          raise ValueError(
              "Image should not have values greater than 255."
          )
  
      # extract stain of the image
      he = self.stain_extractor(image)
  
      # reshape image and calculate absorbance
      h, w, _ = image.shape
      image = image.reshape((-1, 3))
      image = image.astype(np.float32) + 1.0
      absorbance = -np.log(image.clip(max=self.tli) / self.tli)
  
      # rows correspond to channels (RGB), columns to absorbance values
      y = np.reshape(absorbance, (-1, 3)).T
  
      # determine concentrations of the individual stains
      conc = np.linalg.lstsq(he, y, rcond=None)[0]
  
      # normalize stain concentrations
      max_conc = np.asarray(
          [
              np.percentile(conc[0, :], 99),
              np.percentile(conc[1, :], 99),
          ],
          dtype=np.float32,
      )
      tmp = np.divide(max_conc, self.max_cref, dtype=np.float32)
      image_c = np.divide(conc, tmp[:, np.newaxis], dtype=np.float32)
  
      image_norm: np.ndarray = np.multiply(
          self.tli,
          np.exp(-self.target_he.dot(image_c)),
          dtype=np.float32,
      )
      image_norm[image_norm > 255] = 254
      image_norm = np.reshape(image_norm.T, (h, w, 3)).astype(np.uint8)
      return image_norm
  
file_path: MONAI/monai/apps/pathology/transforms/stain/array.py
imports: from __future__ import annotations
  import numpy
  from monai.transforms.transform import Transform
label_desc: Use image node_id 2 for calling the NormalizeHEStains obj's underlying member method code with example usage: obj.__call__(image) and returns: image_norm