def forward(self, img: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
        """Apply augmentation using the mask for single image or batch.

        Args:
            img: Input image tensor of shape ``[C, H, W]`` or batch tensor of shape
                ``[B, C, H, W]``.

        Returns:
            tuple[torch.Tensor, torch.Tensor]: Tuple containing:
                - Augmented image tensor of same shape as input
                - Mask tensor of shape ``[1, H, W]`` or ``[B, 1, H, W]``
        """
        device = img.device
        is_batch = len(img.shape) == 4

        if is_batch:
            batch, _, height, width = img.shape
            # Initialize batch outputs
            batch_augmented = []
            batch_masks = []

            for i in range(batch):
                # Apply transform to each image in batch
                augmented, mask = self._transform_image(img[i], height, width, device)
                batch_augmented.append(augmented)
                batch_masks.append(mask)

            return torch.stack(batch_augmented), torch.stack(batch_masks)

        # Handle single image
        return self._transform_image(img, img.shape[1], img.shape[2], device)
Apply augmentation using the mask for single image or batch.

        Args:
            img: Input image tensor of shape ``[C, H, W]`` or batch tensor of shape
                ``[B, C, H, W]``.

        Returns:
            tuple[torch.Tensor, torch.Tensor]: Tuple containing:
                - Augmented image tensor of same shape as input
                - Mask tensor of shape ``[1, H, W]`` or ``[B, 1, H, W]``
        
src/anomalib/data/utils/generators/perlin.py