Skip to content

feat(apps): add impact-reg-konfai registration orchestrator - #19

Merged
vboussot merged 2 commits into
mainfrom
pr/reg
Jul 3, 2026
Merged

feat(apps): add impact-reg-konfai registration orchestrator#19
vboussot merged 2 commits into
mainfrom
pr/reg

Conversation

@vboussot

@vboussot vboussot commented Jul 3, 2026

Copy link
Copy Markdown
Member

📚 Stacked on #18 (pr/seg). The diff is against pr/seg.

Summary

Adds impact-reg-konfai, a standalone CLI app bundle (apps/impact_reg/) that orchestrates IMPACT-Reg multimodal registration presets through the konfai-apps runtime. Each preset is a self-contained KonfAI app (default repo VBoussot/ImpactReg) whose model emits, on the fixed grid, the resampled moving image and a displacement field. This wrapper adds the registration-specific glue that does not fit the generic konfai-apps pipeline — multi-preset DVF ensembling, modality-aware evaluation, and ensemble-spread uncertainty — as three composable sub-commands so a UI or CLI can drive each step independently. It mirrors the impact-seg-konfai bundle from the base PR, giving registration the same thin-wrapper packaging.

What changed

New app package (apps/impact_reg/impact_reg_konfai/)

  • impact_reg.pyImpactRegKonfAIApp with three operations mirroring konfai-apps infer/eval/uncertainty:
    • register() runs each selected preset via a separate konfai-apps infer subprocess (isolating konfai's process-global Config singleton and KONFAI_* env), averages the per-preset DVFs through _ensemble(), and writes Moved.mha, DVF.mha, and Transform.h5 per case (P%03d). Masks are optional and restrict the metric region; a whole-image mask is auto-filled via _full_mask() so every preset receives its four declared inputs. keep_dvf persists per-preset fields under Ensemble/ for later uncertainty.
    • evaluate() scores any subset of modalities — image MAE (Evaluation_with_images.yml), segmentation Dice with nearest-neighbor resampling (Evaluation_with_seg.yml), and landmark TRE (Evaluation_with_fid.yml) — delegating to KonfAIApp.evaluate. Landmarks warp the fixed fiducials forward through the fixed→moving transform and compare against the moving fiducials (no field inversion).
    • uncertainty() stacks ≥2 ensemble DVFs into one multi-component volume (samples as vector components, real fixed-grid geometry preserved on the trailing axes) and runs the preset's generic Uncertainty.yml (Norm then StandardDeviation) via konfai-apps uncertainty.
    • get_available_presets() / _app_id() resolve presets from a local directory (folders whose app.json declares task == "registration") or the HF repo, overridable via KONFAI_IMPACTREG_REPO (default VBoussot/ImpactReg).
  • cli.pyimpact-reg-konfai argparse front end with register / eval / uncertainty sub-commands: a shared _add_device() (mutually exclusive --gpu/--cpu, -q/--quiet, --download, --force_update), a _default_preset() fallback with an actionable error when none resolve (used by eval/uncertainty), register taking positional presets to ensemble plus --fixed-mask/--moving-mask, --tta, and --uncertainty (keep per-preset DVFs), and an eval guard requiring at least one complete modality (image/seg/fid).
  • Reuses only public API: read_landmarks, write_landmarks, apply_to_data_transform (konfai), KonfAIApp, get_available_apps_on_hf_repo (konfai_apps).

Packaging & docs

  • pyproject.toml declares impact-reg-konfai with a dynamic setuptools-scm version and the impact-reg-konfai = impact_reg_konfai.cli:main entry point; setup.py pins konfai==<version> and konfai-apps==<version> to the same release.
  • Adds LICENSE (Apache-2.0), README.md, Logo.png, and .gitignore; the orchestrator, CLI, and test modules carry the Apache-2.0 SPDX header.

Testing

  • Adds tests/test_evaluate_landmark_direction.py, a regression test locking the landmark transform direction in ImpactRegKonfAIApp.evaluate. With a known translation T: fixed → moving and m_i = T(f_i), it monkeypatches KonfAIApp.__init__/evaluate and asserts the metric's reference is the moving fiducial set while the scored points are the fixed fiducials warped by T, so a perfect transform yields TRE ≈ 0 (not doubled). It uses synthetic data and does not exercise real inference.
  • No changes to the core konfai package or konfai-apps; the PR only adds files under apps/impact_reg/.

Review notes

  • Stacked PR: base is pr/seg. The diff is fully additive — 10 new files, no existing file modified — so there is no core or konfai-apps behavior change and no backward-compatibility risk. Review after the base merges.
  • Runtime behavior depends on network/Hugging Face access to VBoussot/ImpactReg (or a local dir via KONFAI_IMPACTREG_REPO) and shells out to the konfai-apps CLI (subprocess.run(..., check=True), annotated # nosec B603). Per the app trust model, resolving a preset copies/imports its .py and installs its requirements.txt.
  • The two version pins in setup.py assume konfai, konfai-apps, and this package are released in lockstep.

@vboussot vboussot changed the title feat(apps): add impact-reg-konfai (IMPACT registration orchestrator) feat(apps): add impact-reg-konfai registration orchestrator Jul 3, 2026
Base automatically changed from pr/seg to pr/modif-core July 3, 2026 18:50
Base automatically changed from pr/modif-core to main July 3, 2026 19:21
@vboussot
vboussot merged commit 203a8d1 into main Jul 3, 2026
41 checks passed
@vboussot
vboussot deleted the pr/reg branch July 3, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant