class_docstr: RandomTransplantation augmentation.
  
  .. image:: _static/img/RandomTransplantation.png
  
  Randomly transplant (copy and paste) image features and corresponding segmentation masks between images in a batch.
  The transplantation transform works as follows:
  
      1. Based on the parameter `p`, a certain number of images in the batch are selected as acceptor of a
         transplantation.
      2. For each acceptor, the image below in the batch is selected as donor (via circling: :math:`i - 1 \mod B`).
      3. From the donor, a random label is selected and the corresponding image features and segmentation mask are
         transplanted to the acceptor.
  
  The augmentation is described in `Semantic segmentation of surgical hyperspectral images under geometric domain
  shifts` :cite:`sellner2023semantic`.
  
  Args:
      excluded_labels: sequence of labels which should not be transplanted from a donor. This can be useful if only
        parts of the image are annotated and the non-annotated regions (with a specific label index) should be
        excluded from the augmentation. If no label is left in the donor image, nothing is transplanted.
      p: probability for applying an augmentation to an image. This parameter controls how many images in a batch
        receive a transplant.
      p_batch: probability for applying an augmentation to a batch. This param controls the augmentation
        probabilities batch-wise.
      data_keys: the input type sequential for applying augmentations. There must be at least one "mask" tensor. If no
        data keys are given, the first tensor is assumed to be `DataKey.INPUT` and the second tensor `DataKey.MASK`.
        Accepts "input", "mask".
  
  Note:
      - This augmentation requires that segmentation masks are available for all images in the batch and that at
        least some objects in the image are annotated.
      - When using this class directly (`RandomTransplantation()(...)`), it works for arbitrary spatial dimensions
        including 2D and 3D images. When wrapping in :class:`kornia.augmentation.AugmentationSequential`, use
        :class:`kornia.augmentation.RandomTransplantation` for 2D and
        :class:`kornia.augmentation.RandomTransplantation3D` for 3D images.
  
  Inputs:
      - Segmentation mask tensor which is used to determine the objects for transplantation: :math:`(B, *)`.
      - (optional) Additional image or mask tensors where the features are transplanted based on the first
        segmentation mask: :math:`(B, C, *)` (`DataKey.INPUT`) or :math:`(B, *)` (`DataKey.MASK`).
  
  Returns:
      Tensor | list[Tensor]:
  
      Tensor:
          - Augmented mask tensors: :math:`(B, *)`.
      list[Tensor]:
          - Augmented mask tensors: :math:`(B, *)`.
          - Additional augmented image or mask tensors: :math:`(B, C, *)` (`DataKey.INPUT`) or :math:`(B, *)`
            (`DataKey.MASK`).
  
  Examples:
      >>> import torch
      >>> rng = torch.manual_seed(0)
      >>> aug = RandomTransplantation(p=1.)
      >>> image = torch.randn(2, 3, 5, 5)
      >>> mask = torch.randint(0, 3, (2, 5, 5))
      >>> mask
      tensor([[[0, 0, 1, 1, 0],
               [1, 2, 0, 0, 0],
               [1, 2, 1, 1, 0],
               [0, 0, 0, 0, 2],
               [2, 2, 2, 0, 2]],
      <BLANKLINE>
              [[2, 0, 0, 2, 1],
               [2, 1, 0, 2, 1],
               [2, 0, 1, 0, 2],
               [2, 2, 2, 0, 2],
               [2, 1, 0, 0, 0]]])
      >>> image_out, mask_out = aug(image, mask)
      >>> image_out.shape
      torch.Size([2, 3, 5, 5])
      >>> mask_out.shape
      torch.Size([2, 5, 5])
      >>> mask_out
      tensor([[[2, 0, 1, 2, 0],
               [2, 2, 0, 2, 0],
               [2, 2, 1, 1, 2],
               [2, 2, 2, 0, 2],
               [2, 2, 2, 0, 2]],
      <BLANKLINE>
              [[0, 0, 0, 2, 0],
               [2, 1, 0, 0, 0],
               [2, 0, 1, 0, 0],
               [0, 0, 0, 0, 2],
               [2, 1, 0, 0, 0]]])
      >>> aug._params["selected_labels"]  # Image 0 received label 2 from image 1 and image 1 label 0 from image 0
      tensor([2, 0])
  
  You can apply the same augmentation again in which case the same objects get transplanted between the images:
  
      >>> aug._params["selection"]  # The pixels (objects) which get transplanted
      tensor([[[ True, False, False,  True, False],
               [ True, False, False,  True, False],
               [ True, False, False, False,  True],
               [ True,  True,  True, False,  True],
               [ True, False, False, False, False]],
      <BLANKLINE>
              [[ True,  True, False, False,  True],
               [False, False,  True,  True,  True],
               [False, False, False, False,  True],
               [ True,  True,  True,  True, False],
               [False, False, False,  True, False]]])
      >>> image2 = torch.zeros(2, 3, 5, 5)
      >>> image2[1] = 1
      >>> image2[:, 0]
      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.]],
      <BLANKLINE>
              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]]])
      >>> image_out2, mask_out2 = aug(image2, mask, params=aug._params)
      >>> image_out2[:, 0]
      tensor([[[1., 0., 0., 1., 0.],
               [1., 0., 0., 1., 0.],
               [1., 0., 0., 0., 1.],
               [1., 1., 1., 0., 1.],
               [1., 0., 0., 0., 0.]],
      <BLANKLINE>
              [[0., 0., 1., 1., 0.],
               [1., 1., 0., 0., 0.],
               [1., 1., 1., 1., 0.],
               [0., 0., 0., 0., 1.],
               [1., 1., 1., 0., 1.]]])
code: def transform_mask(self, acceptor: Tensor, donor: Tensor, selection: Tensor) -> Tensor:  # type: ignore[override]
      acceptor[selection] = donor[selection]
      return acceptor
  
file_path: kornia/kornia/augmentation/_2d/mix/transplantation.py
imports: from __future__ import annotations
  from typing import Any, Optional, Sequence, Union
  import torch
  from kornia.augmentation._2d.mix.base import MixAugmentationBaseV2
  from kornia.augmentation.utils import _validate_input_dtype
  from kornia.constants import DataKey
  from kornia.core import Tensor, tensor
  from kornia.core.check import KORNIA_CHECK
label_desc: Use image node_id 4 for calling the RandomTransplantation obj's underlying member method code with example usage: obj.transform_mask(acceptor, donor, selection) and returns: acceptor