1 import numpy as np; from _utils.palette_maps import palette_cmap, palette_stops, contrast_text 2 import matplotlib.pyplot as plt 3 from matplotlib.patches import Rectangle 4 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten 5 setup_style() 6 7 np.random.seed(42) 8 methods = ['Input', 'Ours', 'Method A', 'Method B', 'Ground Truth'] 9 n_samples = 2 10 11 # Simulated metrics (PSNR/SSIM) 12 psnr_scores = { 13 'Ours': [32.5, 31.8], 'Method A': [28.3, 27.9], 'Method B': [26.1, 25.5] 14 } 15 ssim_scores = { 16 'Ours': [0.95, 0.94], 'Method A': [0.88, 0.87], 'Method B': [0.82, 0.81] 17 } 18 19 fig, axes = plt.subplots(n_samples * 2, len(methods), figsize=(13, 8)) # 2 rows per sample: image + error 20 21 for i in range(n_samples): 22 for j, method in enumerate(methods): 23 # Image row 24 ax = axes[i * 2, j] 25 img = np.random.rand(64, 64, 3) * 0.3 26 if method == 'Ours': 27 img += 0.45 28 elif method == 'Ground Truth': 29 img += 0.5 30 elif method == 'Input': 31 img += 0.15 32 else: 33 img += 0.3 34 img = np.clip(img, 0, 1) 35 ax.imshow(img) 36 ax.axis('off') 37 38 # Red box highlight on key region 39 if method not in ['Input', 'Ground Truth']: 40 rect = Rectangle((10, 10), 20, 20, linewidth=1.5, edgecolor=COLORS['down'], 41 facecolor='none', linestyle='-') 42 ax.add_patch(rect) 43 44 # Title with scores 45 if i == 0: 46 title = method 47 if method in psnr_scores: 48 title += f'\n{psnr_scores[method][i]:.1f}/{ssim_scores[method][i]:.2f}' 49 fontw = 'bold' if method == 'Ours' else 'normal' 50 color = PALETTE[0] if method == 'Ours' else COLORS['text'] 51 ax.set_title(title, fontsize=8.5, fontweight=fontw, color=color) 52 53 # Error map row 54 ax_err = axes[i * 2 + 1, j] 55 if method in ['Input', 'Ground Truth']: 56 ax_err.axis('off') 57 if method == 'Ground Truth' and i == 0: 58 ax_err.text(0.5, 0.5, 'Error Map\n(|pred - GT|)', ha='center', va='center', 59 fontsize=7, color=COLORS['ref_line'], transform=ax_err.transAxes) 60 else: 61 error = np.random.rand(64, 64) * (0.1 if method == 'Ours' else 0.3 if method == 'Method A' else 0.5) 62 ax_err.imshow(error, cmap=palette_cmap('sequential'), vmin=0, vmax=0.5) 63 ax_err.axis('off') 64 # PSNR/SSIM annotation 65 if method in psnr_scores: 66 ax_err.text(0.5, -0.05, f'PSNR: {psnr_scores[method][i]:.1f} | SSIM: {ssim_scores[method][i]:.2f}', 67 ha='center', va='top', fontsize=6.5, color=COLORS['text'], 68 transform=ax_err.transAxes) 69 70 fig.tight_layout(pad=0.5, h_pad=0.3) 71 save_fig(fig, 'figures/fig_qualitative.pdf')