code: def solarize(tens: Tensor, threshold: int = 128) -> Tensor:
      r"""
          Invert all pixel values above a threshold.
  
      Args:
          tens (Tensor): The image to solarize.
          threshold (int): All pixels above this grayscale level are inverted.
  
      Returns:
          Solarized image (Tensor)
  
      Examples::
  
          >> tens = caer.data.sunrise()
          >> solarized = caer.solarize(tens, threshold=128)
          >> solarized.shape
          (427,640,3)
  
      """
      tens = to_tensor(tens, override_checks=True)
      max_val = MAX_VALUES_BY_DTYPE[tens.dtype]
  
      if tens.dtype == np.dtype("uint8"):
          lut = [(i if i < threshold else max_val - i) for i in range(max_val + 1)]  # type: ignore[call-overload]
  
          prev_shape = tens.shape
          tens = cv.LUT(tens, np.array(lut, dtype=tens.dtype))
  
          if len(prev_shape) != len(tens.shape):
              tens = np.expand_dims(tens, -1)
  
          return to_tensor(tens, override_checks=True)
  
      result_tens = tens.copy()
      cond = tens >= threshold
      result_tens[cond] = max_val - result_tens[cond]
      return to_tensor(result_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 18 for calling a global function with example usage: solarize(tens, threshold) and returns: to_tensor, to_tensor