code: def posterize(img, bits):
      """Reduce the number of bits for each color channel.
  
      Args:
          img (numpy.ndarray): image to posterize.
          bits (int): number of high bits. Must be in range [0, 8]
  
      Returns:
          numpy.ndarray: Image with reduced color channels.
  
      """
      bits = np.uint8(bits)
  
      if img.dtype != np.uint8:
          raise TypeError("Image must have uint8 channel type")
      if np.any((bits < 0) | (bits > 8)):
          raise ValueError("bits must be in range [0, 8]")
  
      if not bits.shape or len(bits) == 1:
          if bits == 0:
              return np.zeros_like(img)
          if bits == 8:
              return img.copy()
  
          lut = np.arange(0, 256, dtype=np.uint8)
          mask = ~np.uint8(2 ** (8 - bits) - 1)
          lut &= mask
  
          return cv2.LUT(img, lut)
  
      if not is_rgb_image(img):
          raise TypeError("If bits is iterable image must be RGB")
  
      result_img = np.empty_like(img)
      for i, channel_bits in enumerate(bits):
          if channel_bits == 0:
              result_img[..., i] = np.zeros_like(img[..., i])
          elif channel_bits == 8:
              result_img[..., i] = img[..., i].copy()
          else:
              lut = np.arange(0, 256, dtype=np.uint8)
              mask = ~np.uint8(2 ** (8 - channel_bits) - 1)
              lut &= mask
  
              result_img[..., i] = cv2.LUT(img[..., i], lut)
  
      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 8 for calling a global function with example usage: posterize(img, bits) and returns: result_img, cv2, np, img