def forward(self, batch_shape: tuple[int, ...], same_on_batch: bool = False) -> dict[str, Tensor]:
        r"""Generate Salt and Pepper noise masks for a batch of images."""
        batch_size, C, H, W = batch_shape
        _common_param_check(batch_size, same_on_batch)
        _device, _dtype = _extract_device_dtype([self.amount, self.salt_and_pepper])

        amount_factor = _adapted_rsampling((batch_size,), self.amount_sampler, same_on_batch).to(
            device=_device, dtype=_dtype
        )
        salt_and_pepper_factor = _adapted_rsampling((batch_size,), self.salt_and_pepper_sampler, same_on_batch).to(
            device=_device, dtype=_dtype
        )

        ## Generate noise masks.
        mask_noise = _adapted_uniform(
            (batch_size, 1, H, W), low=0.0, high=1.0, same_on_batch=same_on_batch
        ) < amount_factor.view(batch_size, 1, 1, 1)
        mask_salt = _adapted_uniform(
            (batch_size, 1, H, W), low=0.0, high=1.0, same_on_batch=same_on_batch
        ) < salt_and_pepper_factor.view(batch_size, 1, 1, 1)

        # If the number of channels is greater than one (3), replicate the generated mask for each channel.
        if C > 1:
            mask_noise = mask_noise.repeat(1, C, 1, 1)
            mask_salt = mask_salt.repeat(1, C, 1, 1)
        mask_pepper = (~mask_salt & mask_noise).to(device=_device)
        mask_salt = (mask_salt & mask_noise).to(device=_device)

        return {
            "amount_factor": amount_factor,
            "salt_and_pepper_factor": salt_and_pepper_factor,
            "mask_salt": mask_salt,
            "mask_pepper": mask_pepper,
        }
Generate Salt and Pepper noise masks for a batch of images.
kornia/augmentation/random_generator/_2d/salt_pepper_noise.py