code: def impulse_noise(
      x: np.ndarray, amount: float, xrange: tuple = None
  ) -> np.ndarray:
      """
      Inject salt & pepper noise.
  
      Parameters
      ----------
      x
          Instance to be perturbed.
      amount
          Proportion of pixels to replace with noise.
      xrange
          Tuple with min and max data range.
  
      Returns
      -------
      Perturbed instance.
      """
      if isinstance(xrange, tuple):
          xmin, xmax = xrange[0], xrange[1]
      else:
          xmin, xmax = x.min(), x.max()
      x_sc = (x - xmin) / (xmax - xmin)  # scale to [0,1]
      x_in = sk.util.random_noise(
          x_sc, mode="s&p", amount=amount
      )  # inject noise
      x_in = x_in * (xmax - xmin) + xmin  # scale back
      if isinstance(xrange, tuple):
          return np.clip(x_in, xrange[0], xrange[1])
      else:
          return x_in
  
imports: import random
  from io import BytesIO
  from typing import List, Tuple, Union
  import cv2
  import numpy
  import skimage
  from alibi_detect.utils.data import Bunch
  from alibi_detect.utils.discretizer import Discretizer
  from alibi_detect.utils.distance import abdm, multidim_scaling
  from alibi_detect.utils.mapping import ohe2ord
  from PIL import Image
  from scipy.ndimage import zoom
  from scipy.ndimage.interpolation import map_coordinates
  from skimage.filters import gaussian
label_desc: Use image node_id 9 for calling a global function with example usage: impulse_noise(x, amount, xrange) and returns: np, x_in