olivas/backend/app/services/image_processing.py
DJP 3467dbcf03 Initial commit — OliVAS visual attention analysis platform
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>
2026-02-23 20:20:58 -05:00

24 lines
832 B
Python

import numpy as np
from PIL import Image
from scipy.ndimage import zoom
MAX_INFERENCE_SIZE = 1024
def prepare_for_inference(image: Image.Image) -> tuple[Image.Image, float]:
"""Resize for model input. Returns (resized_image, scale_factor)."""
w, h = image.size
scale = MAX_INFERENCE_SIZE / max(w, h)
if scale < 1.0:
new_size = (int(w * scale), int(h * scale))
return image.resize(new_size, Image.LANCZOS), scale
return image, 1.0
def upscale_saliency(saliency: np.ndarray, target_h: int, target_w: int) -> np.ndarray:
"""Upscale saliency map to original image dimensions."""
if saliency.shape == (target_h, target_w):
return saliency
h_scale = target_h / saliency.shape[0]
w_scale = target_w / saliency.shape[1]
return zoom(saliency, (h_scale, w_scale), order=1)