diff --git a/scripts/viewer.py b/scripts/viewer.py index 600011d..094288f 100644 --- a/scripts/viewer.py +++ b/scripts/viewer.py @@ -233,55 +233,66 @@ ssim_csv = RESULTS_DIR / "summary_ssim.csv" if ssim_csv.exists(): st.header("再現性評価 (Reproducibility)") - # summary_ssim.csv の 1 行目(集計統計)を読み込んで表示 ssim_stats = pandas.read_csv(ssim_csv, nrows=1) - # 位置合わせなし SSIM - st.subheader("位置合わせなし SSIM (Raw SSIM)") - col1, col2, col3, col4 = st.columns(4) - col1.metric("平均 SSIM", f"{ssim_stats['mean_ssim'].iloc[0]:.6f}") - col2.metric("最小 SSIM", f"{ssim_stats['min_ssim'].iloc[0]:.6f}") - col3.metric("最大 SSIM", f"{ssim_stats['max_ssim'].iloc[0]:.6f}") - col4.metric("標準偏差", f"{ssim_stats['std_ssim'].iloc[0]:.6f}") - - # 位置合わせ後 SSIM(列が存在する場合のみ表示) + # 位置合わせ後の列が存在するか判定 has_registered = ( "mean_ssim_registered" in ssim_stats.columns and pandas.notna(ssim_stats["mean_ssim_registered"].iloc[0]) and ssim_stats["mean_ssim_registered"].iloc[0] != "" ) + + # テーブルデータを構築 + rows: list[dict] = [ + { + "統計量": "平均", + "SSIM(位置合わせなし)": f"{ssim_stats['mean_ssim'].iloc[0]:.6f}", + }, + { + "統計量": "最小", + "SSIM(位置合わせなし)": f"{ssim_stats['min_ssim'].iloc[0]:.6f}", + }, + { + "統計量": "最大", + "SSIM(位置合わせなし)": f"{ssim_stats['max_ssim'].iloc[0]:.6f}", + }, + { + "統計量": "標準偏差", + "SSIM(位置合わせなし)": f"{ssim_stats['std_ssim'].iloc[0]:.6f}", + }, + ] + if has_registered: - st.subheader("位置合わせ後 SSIM (Registered SSIM)") - rcol1, rcol2, rcol3, rcol4 = st.columns(4) - rcol1.metric( - "平均 SSIM (登録後)", - f"{float(ssim_stats['mean_ssim_registered'].iloc[0]):.6f}", + for i, key in enumerate( + [ + "mean_ssim_registered", + "min_ssim_registered", + "max_ssim_registered", + "std_ssim_registered", + ] + ): + rows[i]["SSIM(位置合わせ後)"] = ( + f"{float(ssim_stats[key].iloc[0]):.6f}" + ) + + # シフト量の行を追加 + rows.append( + { + "統計量": "平均シフト量 (px)", + "SSIM(位置合わせなし)": "—", + "SSIM(位置合わせ後)": f"{float(ssim_stats['mean_shift_magnitude'].iloc[0]):.4f}", + } ) - rcol2.metric( - "最小 SSIM (登録後)", - f"{float(ssim_stats['min_ssim_registered'].iloc[0]):.6f}", - ) - rcol3.metric( - "最大 SSIM (登録後)", - f"{float(ssim_stats['max_ssim_registered'].iloc[0]):.6f}", - ) - rcol4.metric( - "標準偏差 (登録後)", - f"{float(ssim_stats['std_ssim_registered'].iloc[0]):.6f}", + rows.append( + { + "統計量": "最大シフト量 (px)", + "SSIM(位置合わせなし)": "—", + "SSIM(位置合わせ後)": f"{float(ssim_stats['max_shift_magnitude'].iloc[0]):.4f}", + } ) - # シフト量メトリクス - st.subheader("シフト量 (Shift Magnitude)") - scol1, scol2 = st.columns(2) - scol1.metric( - "平均シフト (px)", - f"{float(ssim_stats['mean_shift_magnitude'].iloc[0]):.4f}", - ) - scol2.metric( - "最大シフト (px)", - f"{float(ssim_stats['max_shift_magnitude'].iloc[0]):.4f}", - ) - + ssim_table = pandas.DataFrame(rows) + st.dataframe(ssim_table, use_container_width=True, hide_index=True) st.caption("※ SSIM は 1.0 に近いほど画像間の構造的類似度が高く,再現性が良好")