parameters: (img, padding, fill_value, padding_mode)
return_statement: return Image.fromarray(img)
docstring: Pad the image according to padding parameters.
  
      Args:
          img (PIL image): Image to be padded.
          padding (Union[int, sequence], optional): The number of pixels to pad the image.
              If a single number is provided, it pads all borders with this value.
              If a tuple or lists of 2 values are provided, it pads the (left and top)
              with the first value and (right and bottom) with the second value.
              If 4 values are provided as a list or tuple,
              it pads the left, top, right and bottom respectively.
              Default is None.
          fill_value (Union[int, tuple]): The pixel intensity of the borders if
              the padding_mode is "constant". If it is a 3-tuple, it is used to
              fill R, G, B channels respectively.
          padding_mode (str): The method of padding. Can be any of ['constant', 'edge', 'reflect', 'symmetric'].
  
                - 'constant', means it fills the border with constant values
                - 'edge', means it pads with the last value on the edge
                - 'reflect', means it reflects the values on the edge omitting the last
                  value of edge
                - 'symmetric', means it reflects the values on the edge repeating the last
                  value of edge
  
      Returns:
          img (PIL image), Padded image.
docstring_summary: Pad the image according to padding parameters.
docstring_tokens: Pad the image according to padding parameters .
function: def pad(img, padding, fill_value, padding_mode):
      """
      Pad the image according to padding parameters.
  
      Args:
          img (PIL image): Image to be padded.
          padding (Union[int, sequence], optional): The number of pixels to pad the image.
              If a single number is provided, it pads all borders with this value.
              If a tuple or lists of 2 values are provided, it pads the (left and top)
              with the first value and (right and bottom) with the second value.
              If 4 values are provided as a list or tuple,
              it pads the left, top, right and bottom respectively.
              Default is None.
          fill_value (Union[int, tuple]): The pixel intensity of the borders if
              the padding_mode is "constant". If it is a 3-tuple, it is used to
              fill R, G, B channels respectively.
          padding_mode (str): The method of padding. Can be any of ['constant', 'edge', 'reflect', 'symmetric'].
  
                - 'constant', means it fills the border with constant values
                - 'edge', means it pads with the last value on the edge
                - 'reflect', means it reflects the values on the edge omitting the last
                  value of edge
                - 'symmetric', means it reflects the values on the edge repeating the last
                  value of edge
  
      Returns:
          img (PIL image), Padded image.
      """
      if not is_pil(img):
          raise TypeError(augment_error_message.format(type(img)))
  
      if isinstance(padding, numbers.Number):
          top = bottom = left = right = padding
  
      elif isinstance(padding, (tuple, list)):
          if len(padding) == 2:
              left = top = padding[0]
              right = bottom = padding[1]
          elif len(padding) == 4:
              left = padding[0]
              top = padding[1]
              right = padding[2]
              bottom = padding[3]
          else:
              raise ValueError("The size of the padding list or tuple should be 2 or 4.")
      else:
          raise TypeError("Padding can be any of: a number, a tuple or list of size 2 or 4.")
  
      if not isinstance(fill_value, (numbers.Number, str, tuple)):
          raise TypeError("fill_value can be any of: an integer, a string or a tuple.")
  
      if padding_mode not in ['constant', 'edge', 'reflect', 'symmetric']:
          raise ValueError("Padding mode should be 'constant', 'edge', 'reflect', or 'symmetric'.")
  
      if padding_mode == 'constant':
          if img.mode == 'P':
              palette = img.getpalette()
              image = ImageOps.expand(img, border=(left, top, right, bottom), fill=fill_value)
              image.putpalette(palette)
              return image
          return ImageOps.expand(img, border=(left, top, right, bottom), fill=fill_value)
  
      if img.mode == 'P':
          palette = img.getpalette()
          img = np.asarray(img)
          img = np.pad(img, ((top, bottom), (left, right)), padding_mode)
          img = Image.fromarray(img)
          img.putpalette(palette)
          return img
  
      img = np.asarray(img)
      if len(img.shape) == 3:
          img = np.pad(img, ((top, bottom), (left, right), (0, 0)), padding_mode)
      if len(img.shape) == 2:
          img = np.pad(img, ((top, bottom), (left, right)), padding_mode)
  
      return Image.fromarray(img)
function_tokens: def pad ( img , padding , fill_value , padding_mode ) : if not is_pil ( img ) : raise TypeError ( augment_error_message . format ( type ( img ) ) ) if isinstance ( padding , numbers . Number ) : top = bottom = left = right = padding elif isinstance ( padding , ( tuple , list ) ) : if len ( padding ) == 2 : left = top = padding [ 0 ] right = bottom = padding [ 1 ] elif len ( padding ) == 4 : left = padding [ 0 ] top = padding [ 1 ] right = padding [ 2 ] bottom = padding [ 3 ] else : raise ValueError ( "The size of the padding list or tuple should be 2 or 4." ) else : raise TypeError ( "Padding can be any of: a number, a tuple or list of size 2 or 4." ) if not isinstance ( fill_value , ( numbers . Number , str , tuple ) ) : raise TypeError ( "fill_value can be any of: an integer, a string or a tuple." ) if padding_mode not in [ 'constant' , 'edge' , 'reflect' , 'symmetric' ] : raise ValueError ( "Padding mode should be 'constant', 'edge', 'reflect', or 'symmetric'." ) if padding_mode == 'constant' : if img . mode == 'P' : palette = img . getpalette ( ) image = ImageOps . expand ( img , border = ( left , top , right , bottom ) , fill = fill_value ) image . putpalette ( palette ) return image return ImageOps . expand ( img , border = ( left , top , right , bottom ) , fill = fill_value ) if img . mode == 'P' : palette = img . getpalette ( ) img = np . asarray ( img ) img = np . pad ( img , ( ( top , bottom ) , ( left , right ) ) , padding_mode ) img = Image . fromarray ( img ) img . putpalette ( palette ) return img img = np . asarray ( img ) if len ( img . shape ) == 3 : img = np . pad ( img , ( ( top , bottom ) , ( left , right ) , ( 0 , 0 ) ) , padding_mode ) if len ( img . shape ) == 2 : img = np . pad ( img , ( ( top , bottom ) , ( left , right ) ) , padding_mode ) return Image . fromarray ( img )