code: def add_pattern_bd(
      x: np.ndarray,
      distance: int = 2,
      pixel_value: int = 1,
      channels_first: bool = False,
  ) -> np.ndarray:
      """
      Augments a matrix by setting a checkerboard-like pattern of values some `distance` away from the bottom-right
      edge to 1. Works for single images or a batch of images.
  
      :param x: A single image or batch of images of shape NWHC, NHW, or HC. Pixels will be added to all channels.
      :param distance: Distance from bottom-right walls.
      :param pixel_value: Value used to replace the entries of the image matrix.
      :param channels_first: If the data is provided in channels first format we transpose to NWHC or HC depending on
                             input shape
      :return: Backdoored image.
      """
      x = np.copy(x)
      original_dtype = x.dtype
      shape = x.shape
      if channels_first:
          if len(shape) == 4:
              # Transpose the image putting channels last
              x = np.transpose(x, (0, 2, 3, 1))
          if len(shape) == 2:
              # HC to CH
              x = np.transpose(x)
  
      if len(shape) == 4:
          height, width = x.shape[1:3]
          x[:, height - distance, width - distance, :] = pixel_value
          x[
              :, height - distance - 1, width - distance - 1, :
          ] = pixel_value
          x[:, height - distance, width - distance - 2, :] = pixel_value
          x[:, height - distance - 2, width - distance, :] = pixel_value
      elif len(shape) == 3:
          height, width = x.shape[1:]
          x[:, height - distance, width - distance] = pixel_value
          x[
              :, height - distance - 1, width - distance - 1
          ] = pixel_value
          x[:, height - distance, width - distance - 2] = pixel_value
          x[:, height - distance - 2, width - distance] = pixel_value
      elif len(shape) == 2:
          height, width = x.shape
          x[height - distance, width - distance] = pixel_value
          x[height - distance - 1, width - distance - 1] = pixel_value
          x[height - distance, width - distance - 2] = pixel_value
          x[height - distance - 2, width - distance] = pixel_value
      else:
          raise ValueError(f"Invalid array shape: {shape}")
  
      if channels_first:
          if len(shape) == 4:
              # Putting channels first again
              x = np.transpose(x, (0, 3, 1, 2))
          if len(shape) == 2:
              x = np.transpose(x)
  
      return x.astype(original_dtype)
  
imports: from typing import Optional, Tuple
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: add_pattern_bd(x, distance, pixel_value, channels_first) and returns: x