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

def ricostruttore_v4():
    data = np.load('sasso_v4_final.npz')
    shape = data['shape']
    
    reconstructed_img = np.zeros(shape)
    
    for color in ['r', 'g', 'b']:
        U = data[f'U_{color}']
        S = data[f'S_{color}']
        Vt = data[f'Vt_{color}']
        
        # Ricostruzione: Prodotto delle matrici per far riemergere il volto
        channel_idx = {'r':0, 'g':1, 'b':2}[color]
        reconstructed_img[:,:,channel_idx] = np.dot(U, np.dot(np.diag(S), Vt))
    
    reconstructed_img = np.clip(reconstructed_img, 0, 255).astype(np.uint8)
    Image.fromarray(reconstructed_img).save("VERO_VOLTO_FINALE.png")
    print("SINTESI COMPLETATA: Controlla VERO_VOLTO_FINALE.png")

if __name__ == "__main__":
    ricostruttore_v4()