Repository navigation
ENH: FireANTs registrar, tuned heart/lung presets, Fireants-vs-Greedy #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5d246a4
ENH: FireANTs registrar, tuned heart/lung presets, Fireants-vs-Greedy…
aylward 2eced98
ENH: Fix ruff warnings and coderabbit comments
aylward a50b680
ENH: Add fireants to nightly test config
aylward 3d52f46
ENH: Minor CI test improvement
aylward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ build | |
| __pycache__ | ||
| _version.py | ||
| htmlcov | ||
| .vscode | ||
| .vscode/* | ||
| !.vscode/settings.json | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
experiments/Registration-Fireants_vs_Greedy/affine_diagnostic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| """Affine-only diagnostic: FireANTs vs Greedy on selected heart phases. | ||
|
|
||
| Registers each listed phase to the heart reference frame with an Affine-only | ||
| registrar (FireANTs class defaults vs the tutorial Greedy registrar) and | ||
| records NCC/MSE of the warped image plus the affine matrix summary. | ||
|
|
||
| Usage: | ||
| py affine_diagnostic.py --out experiments/Registration-Fireants_vs_Greedy/results/affine_diagnostic.json | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import logging | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| import itk | ||
| import numpy as np | ||
| import torch | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | ||
|
|
||
| import benchmark | ||
|
|
||
|
|
||
| def affine_summary(transform: itk.Transform) -> dict[str, Any]: | ||
| """Matrix determinant, singular values and translation of an affine.""" | ||
| matrix = itk.array_from_matrix(transform.GetMatrix()) | ||
| singular = np.linalg.svd(matrix, compute_uv=False) | ||
| return { | ||
| "determinant": float(np.linalg.det(matrix)), | ||
| "singular_values": [float(v) for v in singular], | ||
| "translation_mm": [float(v) for v in transform.GetTranslation()], | ||
| } | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Run the diagnostic and write the JSON.""" | ||
| parser = argparse.ArgumentParser(description=__doc__.split("\n")[0]) | ||
| parser.add_argument("--phases", default="3,13,15") | ||
| parser.add_argument("--out", type=Path, required=True) | ||
| args = parser.parse_args() | ||
| logging.basicConfig(level=logging.WARNING) | ||
|
|
||
| files, reference_index = benchmark.load_dataset("heart", False) | ||
| images = [itk.imread(str(path)) for path in files] | ||
| reference = images[reference_index] | ||
| fixed_array = itk.array_from_image(reference) | ||
| identity = itk.IdentityTransform[itk.D, 3].New() | ||
|
|
||
| result: dict[str, Any] = {"dataset": "heart", "reference_frame": reference_index} | ||
| rows: dict[str, list[dict[str, Any]]] = {"greedy": [], "fireants": []} | ||
| for method in ("greedy", "fireants"): | ||
| registrar = benchmark.build_registrar("heart", method, False, {}) | ||
| registrar.set_transform_type("Affine") | ||
| registrar.set_fixed_image(reference) | ||
| registrar.register(images[0]) | ||
| for phase in (int(p) for p in args.phases.split(",")): | ||
| moving = images[phase] | ||
| if method == "fireants": | ||
| torch.cuda.synchronize() | ||
| start = time.perf_counter() | ||
| out = registrar.register(moving) | ||
| if method == "fireants": | ||
| torch.cuda.synchronize() | ||
| seconds = time.perf_counter() - start | ||
| forward = out["fixed_to_moving_transform"] | ||
| warped = itk.array_from_image( | ||
| benchmark.resample(moving, forward, reference) | ||
| ) | ||
| unregistered = itk.array_from_image( | ||
| benchmark.resample(moving, identity, reference) | ||
| ) | ||
| rows[method].append( | ||
| { | ||
| "phase": phase, | ||
| "seconds": seconds, | ||
| "ncc": benchmark.ncc(warped, fixed_array), | ||
| "mse": benchmark.mse(warped, fixed_array), | ||
| "ncc_unregistered": benchmark.ncc(unregistered, fixed_array), | ||
| "mse_unregistered": benchmark.mse(unregistered, fixed_array), | ||
| "affine": affine_summary(forward), | ||
| } | ||
| ) | ||
| result["greedy"] = rows["greedy"] | ||
| result["fireants"] = rows["fireants"] | ||
| args.out.parent.mkdir(parents=True, exist_ok=True) | ||
| args.out.write_text(json.dumps(result, indent=2), encoding="utf-8") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.