def apply_transform(
        self,
        input: Tensor,
        params: Dict[str, Tensor],
        flags: Dict[str, Any],
        transform: Optional[Tensor] = None,
    ) -> Tensor:
        r"""Apply random Salt and Pepper noise transformation to the input image."""
        KORNIA_CHECK(len(input.shape) in (3, 4), "Wrong input dimension.")
        if len(input.shape) == 3:
            input = input[None, :, :, :]
        KORNIA_CHECK(input.shape[1] in {3, 1}, "Number of color channels should be 1 or 3.")

        noisy_image = input.clone()

        # Apply noise masks using indexing.
        noisy_image[params["mask_salt"].to(input.device)] = 1.0
        noisy_image[params["mask_pepper"].to(input.device)] = 0.0

        return noisy_image
Apply random Salt and Pepper noise transformation to the input image.
kornia/augmentation/_2d/intensity/salt_pepper_noise.py