def generate_anomaly(self, height: int, width: int) -> Tensor:
        """Generate an anomalous mask using Perlin noise.

        Args:
            height (int): Height of the mask to generate.
            width (int): Width of the mask to generate.

        Returns:
            Tensor: Binary mask of shape ``(1, height, width)`` where ``1``
                indicates anomalous regions.

        Example:
            >>> generator = DsrAnomalyGenerator()
            >>> mask = generator.generate_anomaly(256, 256)
            >>> assert mask.shape == (1, 256, 256)
            >>> assert torch.all((mask >= 0) & (mask <= 1))
        """
        min_perlin_scale = 0
        perlin_scale = 6
        perlin_scalex = int(2 ** torch.randint(min_perlin_scale, perlin_scale, (1,)).item())
        perlin_scaley = int(2 ** torch.randint(min_perlin_scale, perlin_scale, (1,)).item())
        threshold = 0.5

        # Generate perlin noise using the new function
        perlin_noise = generate_perlin_noise(height, width, scale=(perlin_scalex, perlin_scaley))

        # Apply random rotation
        perlin_noise = perlin_noise.unsqueeze(0)  # Add channel dimension for transform
        perlin_noise = self.rot(perlin_noise).squeeze(0)  # Remove channel dimension

        # Create binary mask
        mask = (perlin_noise > threshold).float()
        return mask.unsqueeze(0)  # Add channel dimension [1, H, W]
Generate an anomalous mask using Perlin noise.

        Args:
            height (int): Height of the mask to generate.
            width (int): Width of the mask to generate.

        Returns:
            Tensor: Binary mask of shape ``(1, height, width)`` where ``1``
                indicates anomalous regions.

        Example:
            >>> generator = DsrAnomalyGenerator()
            >>> mask = generator.generate_anomaly(256, 256)
            >>> assert mask.shape == (1, 256, 256)
            >>> assert torch.all((mask >= 0) & (mask <= 1))
        
src/anomalib/models/image/dsr/anomaly_generator.py