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)...") # 将 PDF 的第一页转换为 PIL Image pages = convert_from_path(left_pdf_path, dpi=300) img_l = pages[0] print("正在加载右侧面板...") img_r = Image.open(right_img_path) # 统一高度对齐 (以 1500px 为基准高度进行高质量重采样,保证 PDF 提取的清晰度) 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) # 设置画布,保持两个 Panel 的原始宽高比比例 # 使用更大的 figsize 以容纳高分辨率图像 fig, (ax1, ax2) = plt.subplots( 1, 2, figsize=(18, 6), 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=18, 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=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" # 自动保存到论文的 tex figures 目录 OUTPUT_PREFIX = "/root/autodl-tmp/SplatAtlas/tex/figures/fig1_saturation_puzzle" compose_figure_1(LEFT_PATH, RIGHT_PATH, OUTPUT_PREFIX)