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/ricostruttorev2.py
import numpy as np
from PIL import Image
from scipy.ndimage import zoom

def ricostruttore_v2(matrix_path, output_name="volto_fase_corretta.png"):
    sasso = np.load(matrix_path)
    grid_size = sasso.shape[0]
    
    # Ricostruzione con interpolazione a 4° ordine (Lanczos/Cubic)
    # per evitare la sfocatura (blur) e mantenere le proporzioni
    target_res = 512
    zoom_factor = target_res / grid_size
    
    reconstructed_channels = []
    for c in range(3):
        # L'ordine 5 forza una ricostruzione geometrica più rigida (meno blob)
        chan = zoom(sasso[:,:,c], zoom_factor, order=5)
        reconstructed_channels.append(chan)
        
    img_data = np.stack(reconstructed_channels, axis=2)
    img_data = np.clip(img_data * 255, 0, 255).astype(np.uint8)
    
    final_img = Image.fromarray(img_data)
    final_img.save(output_name)
    print(f"V2: Ricostruzione ultimata in {output_name}")

if __name__ == "__main__":
    ricostruttore_v2('matrice_sasso_v2.npy')