code: def binary_erosion(
      image: Tensor,
      structure: Optional[Tensor] = None,
      origin: Optional[Tuple[int, ...]] = None,
      border_value: int = 0,
  ) -> Tensor:
      """Binary erosion of a tensor image.
  
      Implementation inspired by answer to this question: https://stackoverflow.com/questions/56235733/
  
      Args:
          image: The image to be eroded, must be a binary tensor with shape ``(batch_size, channels, height, width)``.
          structure: The structuring element used for the erosion. If no structuring element is provided, an element
              is generated with a square connectivity equal to one.
          origin: The origin of the structuring element.
          border_value: The value to be used for the border.
  
      Examples::
          >>> from torchmetrics.functional.segmentation.utils import binary_erosion
          >>> import torch
          >>> image = torch.tensor([[[[0, 0, 0, 0, 0],
          ...                         [0, 1, 1, 1, 0],
          ...                         [0, 1, 1, 1, 0],
          ...                         [0, 1, 1, 1, 0],
          ...                         [0, 0, 0, 0, 0]]]])
          >>> binary_erosion(image)
          tensor([[[[0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0],
                    [0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0]]]], dtype=torch.uint8)
          >>> binary_erosion(image, structure=torch.ones(4, 4))
          tensor([[[[0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0]]]], dtype=torch.uint8)
  
      """
      if not isinstance(image, Tensor):
          raise TypeError(
              f"Expected argument `image` to be of type Tensor but found {type(image)}"
          )
      if image.ndim not in [4, 5]:
          raise ValueError(
              f"Expected argument `image` to be of rank 4 or 5 but found rank {image.ndim}"
          )
      check_if_binarized(image)
  
      # construct the structuring element if not provided
      if structure is None:
          structure = (
              generate_binary_structure(image.ndim - 2, 1)
              .int()
              .to(image.device)
          )
      check_if_binarized(structure)
  
      if origin is None:
          origin = structure.ndim * (1,)
  
      # first pad the image to have correct unfolding; here is where the origins is used
      image_pad = pad(
          image,
          [
              x
              for i in range(len(origin))
              for x in [origin[i], structure.shape[i] - origin[i] - 1]
          ],
          mode="constant",
          value=border_value,
      )
      # Unfold the image to be able to perform operation on neighborhoods
      image_unfold = _unfold(
          image_pad.float(), kernel_size=structure.shape
      )
  
      strel_flatten = (
          torch.flatten(structure).unsqueeze(0).unsqueeze(-1)
      )
      sums = image_unfold - strel_flatten.int()
  
      # Take minimum over the neighborhood
      result, _ = sums.min(dim=1)
  
      # Reshape the image to recover initial shape
      return (torch.reshape(result, image.shape) + 1).byte()
  
file_path: torchmetrics/src/torchmetrics/functional/segmentation/utils.py
imports: import functools
  import math
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn.functional import conv2d, conv3d, pad, unfold
  from typing_extensions import Literal
  from torchmetrics.utilities.checks import _check_same_shape
  from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
label_desc: Use image node_id 4 for calling a global function with example usage: binary_erosion(image, structure, origin, border_value) and returns: unknown