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

def sasso_svd_encoding(image_path, k_components=200):
    img = Image.open(image_path).convert('RGB')
    img_array = np.asarray(img, dtype=float)
    
    data_dict = {'shape': img_array.shape}
    
    for i, color in enumerate(['r', 'g', 'b']):
        channel = img_array[:,:,i]
        # Decomposizione ai Valori Singolari: la base del solitone strutturale
        U, S, Vt = np.linalg.svd(channel, full_matrices=False)
        
        # Salvataggio separato delle componenti per evitare l'errore di forma
        data_dict[f'U_{color}'] = U[:, :k_components]
        data_dict[f'S_{color}'] = S[:k_components]
        data_dict[f'Vt_{color}'] = Vt[:k_components, :]
    
    np.savez_compressed('sasso_v4_final.npz', **data_dict)
    print("V4-CORRECTED: Sasso spettrale generato con successo.")

if __name__ == "__main__":
    sasso_svd_encoding("immagine_volto.jpg")