| import matplotlib.pyplot as plt |
| from PIL import Image |
| import os |
| from pdf2image import convert_from_path |
|
|
| def compose_figure_1(left_pdf_path, right_img_path, output_prefix): |
| if not os.path.exists(left_pdf_path): |
| print(f"❌ 找不到左图 (PDF): {left_pdf_path}") |
| return |
| if not os.path.exists(right_img_path): |
| print(f"❌ 找不到右图 (IMG): {right_img_path}") |
| return |
|
|
| print("正在从 PDF 提取左侧面板 (DPI=300)...") |
| |
| pages = convert_from_path(left_pdf_path, dpi=300) |
| img_l = pages[0] |
|
|
| print("正在加载右侧面板...") |
| img_r = Image.open(right_img_path) |
|
|
| |
| target_height = 1500 |
| aspect_l = img_l.width / img_l.height |
| aspect_r = img_r.width / img_r.height |
| |
| new_w_l = int(target_height * aspect_l) |
| new_w_r = int(target_height * aspect_r) |
|
|
| img_l = img_l.resize((new_w_l, target_height), Image.Resampling.LANCZOS) |
| img_r = img_r.resize((new_w_r, target_height), Image.Resampling.LANCZOS) |
|
|
| |
| |
| fig, (ax1, ax2) = plt.subplots( |
| 1, 2, |
| figsize=(18, 6), |
| gridspec_kw={'width_ratios': [aspect_l, aspect_r]} |
| ) |
| |
| |
| ax1.imshow(img_l) |
| ax1.axis('off') |
| ax1.set_title("(a) Per-seed PSNR Rank Instability (BONSAI & LEGO)", |
| fontsize=18, pad=12, loc='left', fontweight='bold') |
|
|
| |
| ax2.imshow(img_r) |
| ax2.axis('off') |
| ax2.set_title("(b) Saturated Cluster: Render vs. Representation", |
| fontsize=18, pad=12, loc='left', fontweight='bold') |
|
|
| |
| plt.subplots_adjust(wspace=0.03) |
| |
| |
| os.makedirs(os.path.dirname(output_prefix), exist_ok=True) |
| pdf_path = f"{output_prefix}.pdf" |
| png_path = f"{output_prefix}.png" |
| |
| print("正在保存最终拼接文件...") |
| plt.savefig(pdf_path, dpi=300, bbox_inches='tight', format='pdf', transparent=True) |
| plt.savefig(png_path, dpi=300, bbox_inches='tight', format='png', transparent=False) |
| |
| print(f"=== Figure 1 (Saturation Puzzle) 拼图合成完毕 ===") |
| print(f"✅ Saved PDF: {pdf_path} (供 LaTeX 插入)") |
| print(f"✅ Saved PNG: {png_path} (供快速预览)") |
|
|
| if __name__ == "__main__": |
| |
| |
| |
| LEFT_PATH = "/root/autodl-tmp/SplatAtlas/outputs/phase5b/fig1_left_panel.pdf" |
| RIGHT_PATH = "/root/autodl-tmp/SplatAtlas/outputs/phase5b/image_1ae31e.jpg" |
| |
| |
| OUTPUT_PREFIX = "/root/autodl-tmp/SplatAtlas/tex/figures/fig1_saturation_puzzle" |
| |
| compose_figure_1(LEFT_PATH, RIGHT_PATH, OUTPUT_PREFIX) |
|
|