Show orthogonal CT triplets in common model space

This commit is contained in:
admin
2026-06-03 10:10:41 +08:00
parent 689660c8bc
commit 972fb2435c
3 changed files with 93 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
"""独立推理模块。
本模块加载官方 ``voxelmorph.nn.models.VxmPairwise`` 训练出的权重,输出:
- fixed_model_input.nii.gz重采样、归一化、裁剪/填充后的 Fixed。
- moving_model_input.nii.gz重采样、归一化、裁剪/填充后的 Moving。
- warped_moving.nii.gz形变后的 Moving。
- ddf_mm.nii.gzDense Displacement Fieldshape = (X, Y, Z, 3),单位 mm。
- metrics.json配准前后 NCC/MSE/MAE 与 DDF 统计。
@@ -143,7 +145,7 @@ def run_inference(
nb_features = checkpoint.get("nb_features", [16, 16, 16, 16, 16])
integration_steps = int(checkpoint.get("integration_steps", 0))
moving_xyz, _ = prepare_nifti_for_model(
moving_xyz, moving_affine = prepare_nifti_for_model(
moving_path,
target_shape_xyz=target_shape_xyz,
target_spacing=target_spacing,
@@ -182,10 +184,14 @@ def run_inference(
out_dir = Path(out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
prepared_moving_path = out_dir / "moving_model_input.nii.gz"
prepared_fixed_path = out_dir / "fixed_model_input.nii.gz"
warped_path = out_dir / "warped_moving.nii.gz"
ddf_path = out_dir / "ddf_mm.nii.gz"
metrics_path = out_dir / "metrics.json"
save_nifti(moving_xyz, moving_affine, prepared_moving_path)
save_nifti(fixed_xyz, fixed_affine, prepared_fixed_path)
save_nifti(warped_xyz, fixed_affine, warped_path)
save_ddf_nifti(ddf_xyz_mm, fixed_affine, ddf_path)
@@ -195,6 +201,8 @@ def run_inference(
{
"moving_path": str(moving_path),
"fixed_path": str(fixed_path),
"prepared_moving_path": str(prepared_moving_path),
"prepared_fixed_path": str(prepared_fixed_path),
"checkpoint_path": str(checkpoint_path),
"warped_path": str(warped_path),
"ddf_path": str(ddf_path),