Download tools/compose_fig1.py from KCBtheone/SplatAtlas: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/tools/compose_fig1.py
- Command line
-
hf download hf://KCBtheone/SplatAtlas/tools/compose_fig1.py
-
curl -L -o compose_fig1.py https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/tools/compose_fig1.py
2.81 kB
| import matplotlib.pyplot as plt | |
| from PIL import Image | |
| import os | |
| def compose_figure_1(left_path, right_path, output_prefix): | |
| if not os.path.exists(left_path): | |
| print(f"❌ 找不到左图: {left_path} \n👉 请手动修改脚本底部的 LEFT_PATH") | |
| return | |
| if not os.path.exists(right_path): | |
| print(f"❌ 找不到右图: {right_path} \n👉 请手动修改脚本底部的 RIGHT_PATH") | |
| return | |
| # 读取图像 | |
| img_l = Image.open(left_path) | |
| img_r = Image.open(right_path) | |
| # 统一高度对齐 (以 1000px 为基准高度进行 Lanczos 高质量重采样) | |
| target_height = 1000 | |
| 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) | |
| # 设置画布,保持两个 Panel 的原始宽高比比例 | |
| fig, (ax1, ax2) = plt.subplots( | |
| 1, 2, | |
| figsize=(16, 5), | |
| gridspec_kw={'width_ratios': [aspect_l, aspect_r]} | |
| ) | |
| # 绘制 Left Panel | |
| ax1.imshow(img_l) | |
| ax1.axis('off') | |
| ax1.set_title("(a) Per-seed PSNR Rank Instability (BONSAI & LEGO)", | |
| fontsize=16, pad=12, loc='left', fontweight='bold') | |
| # 绘制 Right Panel | |
| ax2.imshow(img_r) | |
| ax2.axis('off') | |
| ax2.set_title("(b) Saturated Cluster: Render vs. Representation", | |
| fontsize=16, 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" | |
| 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.png" | |
| RIGHT_PATH = "/root/autodl-tmp/SplatAtlas/outputs/phase5b/image_1ae31e.jpg" | |
| # 自动保存到论文的 tex figures 目录 | |
| OUTPUT_PREFIX = "/root/autodl-tmp/SplatAtlas/tex/figures/fig1_saturation_puzzle" | |
| compose_figure_1(LEFT_PATH, RIGHT_PATH, OUTPUT_PREFIX) | |