code: def _equalize_pil(img, mask=None):
      histogram = cv2.calcHist(
          [img], [0], mask, [256], (0, 256)
      ).ravel()
      h = [_f for _f in histogram if _f]
  
      if len(h) <= 1:
          return img.copy()
  
      step = np.sum(h[:-1]) // 255
      if not step:
          return img.copy()
  
      lut = np.empty(256, dtype=np.uint8)
      n = step // 2
      for i in range(256):
          lut[i] = min(n // step, 255)
          n += histogram[i]
  
      return cv2.LUT(img, np.array(lut))
  
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 9 for calling a global function with example usage: _equalize_pil(img, mask) and returns: cv2, img, img