def superimpose_anomaly_map(
    anomaly_map: np.ndarray,
    image: np.ndarray,
    alpha: float = 0.4,
    gamma: int = 0,
    normalize: bool = False,
) -> np.ndarray:
    """Superimpose an anomaly heatmap on top of an input image.

    This function overlays a colored anomaly map visualization on an input image using
    alpha blending. The anomaly map can optionally be normalized before blending.

    Args:
        anomaly_map (np.ndarray): Grayscale anomaly map computed by the model's
            distance metric. Should be a 2D array of float values.
        image (np.ndarray): Input image to overlay the anomaly map on. Will be
            resized to match anomaly map dimensions.
        alpha (float, optional): Blending weight for the anomaly map overlay.
            Should be in range [0,1] where 0 shows only the input image and 1
            shows only the anomaly map. Defaults to ``0.4``.
        gamma (int, optional): Value added to the blended result for smoothing.
            The blending formula is:
            ``output = (alpha * anomaly_map + (1-alpha) * image) + gamma``
            Defaults to ``0``.
        normalize (bool, optional): Whether to normalize the anomaly map to [0,1]
            range before coloring. If ``True``, uses min-max scaling at the image
            level. Defaults to ``False``.

    Returns:
        np.ndarray: RGB image with the colored anomaly map overlay. Values are in
            range [0,255] and type uint8.

    Examples:
        Basic overlay without normalization:

        >>> result = superimpose_anomaly_map(anomaly_map, image, alpha=0.4)
        >>> result.shape
        (224, 224, 3)
        >>> result.dtype
        dtype('uint8')

        Overlay with normalization and custom blending:

        >>> result = superimpose_anomaly_map(
        ...     anomaly_map,
        ...     image,
        ...     alpha=0.7,
        ...     gamma=10,
        ...     normalize=True
        ... )

    Note:
        - Input image is resized to match anomaly map dimensions
        - Anomaly map is converted to a color heatmap using JET colormap
        - Output maintains RGB color format
        - Shape of output matches the anomaly map dimensions
    """
    anomaly_map = anomaly_map_to_color_map(anomaly_map.squeeze(), normalize=normalize)
    height, width = anomaly_map.shape[:2]
    image = cv2.resize(image, (width, height))
    return cv2.addWeighted(anomaly_map, alpha, image, (1 - alpha), gamma)
Superimpose an anomaly heatmap on top of an input image.

    This function overlays a colored anomaly map visualization on an input image using
    alpha blending. The anomaly map can optionally be normalized before blending.

    Args:
        anomaly_map (np.ndarray): Grayscale anomaly map computed by the model's
            distance metric. Should be a 2D array of float values.
        image (np.ndarray): Input image to overlay the anomaly map on. Will be
            resized to match anomaly map dimensions.
        alpha (float, optional): Blending weight for the anomaly map overlay.
            Should be in range [0,1] where 0 shows only the input image and 1
            shows only the anomaly map. Defaults to ``0.4``.
        gamma (int, optional): Value added to the blended result for smoothing.
            The blending formula is:
            ``output = (alpha * anomaly_map + (1-alpha) * image) + gamma``
            Defaults to ``0``.
        normalize (bool, optional): Whether to normalize the anomaly map to [0,1]
            range before coloring. If ``True``, uses min-max scaling at the image
            level. Defaults to ``False``.

    Returns:
        np.ndarray: RGB image with the colored anomaly map overlay. Values are in
            range [0,255] and type uint8.

    Examples:
        Basic overlay without normalization:

        >>> result = superimpose_anomaly_map(anomaly_map, image, alpha=0.4)
        >>> result.shape
        (224, 224, 3)
        >>> result.dtype
        dtype('uint8')

        Overlay with normalization and custom blending:

        >>> result = superimpose_anomaly_map(
        ...     anomaly_map,
        ...     image,
        ...     alpha=0.7,
        ...     gamma=10,
        ...     normalize=True
        ... )

    Note:
        - Input image is resized to match anomaly map dimensions
        - Anomaly map is converted to a color heatmap using JET colormap
        - Output maintains RGB color format
        - Shape of output matches the anomaly map dimensions
    
src/anomalib/utils/post_processing.py