code: def equalize(img, mask=None, mode="cv", by_channels=True):
      """Equalize the image histogram.
  
      Args:
          img (numpy.ndarray): RGB or grayscale image.
          mask (numpy.ndarray): An optional mask.  If given, only the pixels selected by
              the mask are included in the analysis. Maybe 1 channel or 3 channel array.
          mode (str): {'cv', 'pil'}. Use OpenCV or Pillow equalization method.
          by_channels (bool): If True, use equalization by channels separately,
              else convert image to YCbCr representation and use equalization by `Y` channel.
  
      Returns:
          numpy.ndarray: Equalized image.
  
      """
      if img.dtype != np.uint8:
          raise TypeError("Image must have uint8 channel type")
  
      modes = ["cv", "pil"]
  
      if mode not in modes:
          raise ValueError(
              "Unsupported equalization mode. Supports: {}. "
              "Got: {}".format(modes, mode)
          )
      if mask is not None:
          if is_rgb_image(mask) and is_grayscale_image(img):
              raise ValueError(
                  "Wrong mask shape. Image shape: {}. "
                  "Mask shape: {}".format(img.shape, mask.shape)
              )
          if not by_channels and not is_grayscale_image(mask):
              raise ValueError(
                  "When by_channels=False only 1-channel mask supports. "
                  "Mask shape: {}".format(mask.shape)
              )
  
      if mode == "pil":
          function = _equalize_pil
      else:
          function = _equalize_cv
  
      if mask is not None:
          mask = mask.astype(np.uint8)
  
      if is_grayscale_image(img):
          return function(img, mask)
  
      if not by_channels:
          result_img = cv2.cvtColor(img, cv2.COLOR_RGB2YCrCb)
          result_img[..., 0] = function(result_img[..., 0], mask)
          return cv2.cvtColor(result_img, cv2.COLOR_YCrCb2RGB)
  
      result_img = np.empty_like(img)
      for i in range(3):
          if mask is None:
              _mask = None
          elif is_grayscale_image(mask):
              _mask = mask
          else:
              _mask = mask[..., i]
  
          result_img[..., i] = function(img[..., i], _mask)
  
      return result_img
  
imports: from __future__ import division
  from typing import Optional, Sequence, Union
  from warnings import warn
  import cv2
  import numpy
  import skimage
  from albumentations import random_utils
  from albumentations.augmentations.utils import MAX_VALUES_BY_DTYPE, _maybe_process_in_chunks, clip, clipped, ensure_contiguous, is_grayscale_image, is_rgb_image, non_rgb_warning, preserve_channel_dim, preserve_shape
label_desc: Use image node_id 11 for calling a global function with example usage: equalize(img, mask, mode, by_channels) and returns: result_img, function, cv2