code: def soft_erode(img: torch.Tensor) -> torch.Tensor:  # type: ignore
      """
      Perform soft erosion on the input image
  
      Args:
          img: the shape should be BCH(WD)
  
      Adapted from:
          https://github.com/jocpae/clDice/blob/master/cldice_loss/pytorch/soft_skeleton.py#L6
      """
      if len(img.shape) == 4:
          p1 = -(F.max_pool2d(-img, (3, 1), (1, 1), (1, 0)))
          p2 = -(F.max_pool2d(-img, (1, 3), (1, 1), (0, 1)))
          return torch.min(p1, p2)
      elif len(img.shape) == 5:
          p1 = -(F.max_pool3d(-img, (3, 1, 1), (1, 1, 1), (1, 0, 0)))
          p2 = -(F.max_pool3d(-img, (1, 3, 1), (1, 1, 1), (0, 1, 0)))
          p3 = -(F.max_pool3d(-img, (1, 1, 3), (1, 1, 1), (0, 0, 1)))
          return torch.min(torch.min(p1, p2), p3)
  
file_path: MONAI/monai/losses/cldice.py
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from torch.nn.modules.loss import _Loss
label_desc: Use image node_id 1 for calling a global function with example usage: soft_erode(img) and returns: torch, torch