code: def median_filter2d(
      image: TensorLike,
      filter_shape: Union[int, Iterable[int]] = (3, 3),
      padding: str = "REFLECT",
      constant_values: TensorLike = 0,
      name: Optional[str] = None,
  ) -> tf.Tensor:
      """Perform median filtering on image(s).
  
      Args:
        image: Either a 2-D `Tensor` of shape `[height, width]`,
          a 3-D `Tensor` of shape `[height, width, channels]`,
          or a 4-D `Tensor` of shape `[batch_size, height, width, channels]`.
        filter_shape: An `integer` or `tuple`/`list` of 2 integers, specifying
          the height and width of the 2-D median filter. Can be a single integer
          to specify the same value for all spatial dimensions.
        padding: A `string`, one of "REFLECT", "CONSTANT", or "SYMMETRIC".
          The type of padding algorithm to use, which is compatible with
          `mode` argument in `tf.pad`. For more details, please refer to
          https://www.tensorflow.org/api_docs/python/tf/pad.
        constant_values: A `scalar`, the pad value to use in "CONSTANT"
          padding mode.
        name: A name for this operation (optional).
      Returns:
        2-D, 3-D or 4-D `Tensor` of the same dtype as input.
      Raises:
        ValueError: If `image` is not 2, 3 or 4-dimensional,
          if `padding` is other than "REFLECT", "CONSTANT" or "SYMMETRIC",
          or if `filter_shape` is invalid.
      """
      with tf.name_scope(name or "median_filter2d"):
          image = tf.convert_to_tensor(image, name="image")
          original_ndims = img_utils.get_ndims(image)
          image = img_utils.to_4D_image(image)
  
          filter_shape = keras_utils.normalize_tuple(
              filter_shape, 2, "filter_shape"
          )
  
          image_shape = tf.shape(image)
          batch_size = image_shape[0]
          height = image_shape[1]
          width = image_shape[2]
          channels = image_shape[3]
  
          # Explicitly pad the image
          image = _pad(
              image,
              filter_shape,
              mode=padding,
              constant_values=constant_values,
          )
  
          area = filter_shape[0] * filter_shape[1]
  
          floor = (area + 1) // 2
          ceil = area // 2 + 1
  
          patches = tf.image.extract_patches(
              image,
              sizes=[1, filter_shape[0], filter_shape[1], 1],
              strides=[1, 1, 1, 1],
              rates=[1, 1, 1, 1],
              padding="VALID",
          )
  
          patches = tf.reshape(
              patches, shape=[batch_size, height, width, area, channels]
          )
  
          patches = tf.transpose(patches, [0, 1, 2, 4, 3])
  
          # Note the returned median is casted back to the original type
          # Take [5, 6, 7, 8] for example, the median is (6 + 7) / 2 = 3.5
          # It turns out to be int(6.5) = 6 if the original type is int
          top = tf.nn.top_k(patches, k=ceil).values
          if area % 2 == 1:
              median = top[:, :, :, :, floor - 1]
          else:
              median = (
                  top[:, :, :, :, floor - 1] + top[:, :, :, :, ceil - 1]
              ) / 2
  
          output = tf.cast(median, image.dtype)
          output = img_utils.from_4D_image(output, original_ndims)
          return output
  
file_path: addons/tensorflow_addons/image/filters.py
imports: import tensorflow
  from tensorflow_addons.image import utils
  from tensorflow_addons.utils import keras_utils
  from tensorflow_addons.utils.types import TensorLike
  from typing import Optional, Union, List, Tuple, Iterable
label_desc: Use image node_id 3 for calling a global function with example usage: median_filter2d(image, filter_shape, padding, constant_values, name) and returns: output