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_light.py
import numpy as np
from PIL import Image

def ricostruttore_light():
    data = np.load('sasso_v4_light.npz')
    shape = data['shape']
    
    reconstructed_img = np.zeros(shape)
    
    for color in ['r', 'g', 'b']:
        # Riportiamo in float32 per il calcolo matriciale onde evitare overflow
        U = data[f'U_{color}'].astype(np.float32)
        S = data[f'S_{color}'].astype(np.float32)
        Vt = data[f'Vt_{color}'].astype(np.float32)
        
        channel_idx = {'r':0, 'g':1, 'b':2}[color]
        reconstructed_img[:,:,channel_idx] = np.dot(U, np.dot(np.diag(S), Vt))
    
    # Riconversione finale
    reconstructed_img = np.clip(reconstructed_img * 255, 0, 255).astype(np.uint8)
    Image.fromarray(reconstructed_img).save("VOLTO_OTTIMIZZATO.png")
    print("Ricostruzione completata: controlla VOLTO_OTTIMIZZATO.png")

if __name__ == "__main__":
    ricostruttore_light()