code: def _equalize_cv(tens, mask=None) -> Tensor:
      if mask is None:
          tens = cv.equalizeHist(tens)
          return to_tensor(tens, override_checks=True)
  
      histogram = cv.calcHist(
          [tens], [0], mask, [256], (0, 256)
      ).ravel()
      i = 0
      for val in histogram:
          if val > 0:
              break
          i += 1
      i = min(i, 255)
  
      total = np.sum(histogram)
      if histogram[i] == total:
          tens = np.full_like(tens, i)
          return to_tensor(tens, override_checks=True)
  
      scale = 255.0 / (total - histogram[i])
      _sum = 0
  
      lut = np.zeros(256, dtype=np.uint8)
      i += 1
      for i in range(i, len(histogram)):
          _sum += histogram[i]
          lut[i] = clip(round(_sum * scale), np.dtype("uint8"), 255)  # type: ignore[arg-type]
  
      tens = cv.LUT(tens, lut)
      return to_tensor(tens, override_checks=True)
  
imports: import numpy
  import cv2
  import random
  import collections
  from ..coreten import Tensor, to_tensor
  from .._internal import _check_target_size
  from ..globals import INTER_AREA, INTER_CUBIC, INTER_NEAREST, INTER_LINEAR
  from ..annotations import Union, Tuple, Optional
label_desc: Use image node_id 21 for calling a global function with example usage: _equalize_cv(tens, mask) and returns: to_tensor, to_tensor, to_tensor