Full-stack application for predicting where humans look in images using DeepGaze saliency models. Includes heatmap overlays, gaze sequence prediction, hotspot detection, AOI analysis, rule-based insights, optional Claude AI design analysis, and professional PDF report generation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
918 B
Python
26 lines
918 B
Python
import matplotlib
|
|
matplotlib.use("Agg")
|
|
import matplotlib.cm as cm
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
def generate_heatmap_overlay(
|
|
original: Image.Image,
|
|
saliency: np.ndarray,
|
|
colormap: str = "jet",
|
|
alpha: float = 0.5,
|
|
) -> Image.Image:
|
|
"""Generate heatmap blended over original image."""
|
|
cmap = matplotlib.colormaps.get_cmap(colormap)
|
|
heatmap_rgba = cmap(saliency)
|
|
heatmap_rgb = (heatmap_rgba[:, :, :3] * 255).astype(np.uint8)
|
|
heatmap_img = Image.fromarray(heatmap_rgb).resize(original.size, Image.LANCZOS)
|
|
return Image.blend(original.convert("RGB"), heatmap_img, alpha)
|
|
|
|
|
|
def generate_standalone_heatmap(saliency: np.ndarray, colormap: str = "jet") -> Image.Image:
|
|
"""Generate a pure heatmap image."""
|
|
cmap = matplotlib.colormaps.get_cmap(colormap)
|
|
heatmap_rgba = cmap(saliency)
|
|
return Image.fromarray((heatmap_rgba[:, :, :3] * 255).astype(np.uint8))
|