HEX
Server: Apache/2.4.66 (Ubuntu)
System: Linux nic2 5.15.0-177-generic #187-Ubuntu SMP Sat Apr 11 22:54:33 UTC 2026 x86_64
User: www-data (33)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //test_python/ricostruttore.py
import numpy as np
from PIL import Image
from scipy.ndimage import zoom, gaussian_filter

def reconstruct_from_sasso(matrix_path, output_name="volto_ricostruito.png"):
    # 1. Caricamento della matrice spettrale
    try:
        sasso = np.load(matrix_path)
    except Exception as e:
        print(f"Errore nel caricamento del Sasso: {e}")
        return

    grid_size = sasso.shape[0]
    
    # 2. Sintesi Solitonica Continua
    # Utilizziamo un'interpolazione di ordine superiore per simulare 
    # l'interazione tra i poli (UPO) e ricostruire i gradienti (rughe/sfumature)
    reconstructed_channels = []
    
    # Fattore di upsampling per tornare a una risoluzione visibile (es. 512x512)
    upscale_factor = 512 // grid_size 

    for c in range(3):
        # Prendiamo la matrice zeta del canale
        zeta_map = sasso[:, :, c]
        
        # Applichiamo un filtro di smoothing non lineare per le sfumature
        # Questo simula la propagazione del campo solitonico nello spazio delle fasi
        smooth_map = gaussian_filter(zeta_map, sigma=0.8)
        
        # Ricostruzione continua tramite zoom cubico
        channel_cont = zoom(smooth_map, upscale_factor, order=3)
        reconstructed_channels.append(channel_cont)

    # 3. Assemblaggio e Normalizzazione
    reconstructed_img = np.stack(reconstructed_channels, axis=2)
    
    # Normalizzazione per garantire la visualizzazione corretta nel browser
    reconstructed_img = (reconstructed_img - np.min(reconstructed_img)) / (np.max(reconstructed_img) - np.min(reconstructed_img))
    reconstructed_img = (reconstructed_img * 255).astype(np.uint8)

    # 4. Salvataggio file finale
    final_image = Image.fromarray(reconstructed_img)
    final_image.save(output_name)
    print(f"Ricostruzione completata. File generato: {output_name}")

if __name__ == "__main__":
    reconstruct_from_sasso('matrice_sasso.npy')