Add Allen RAS+ alignment + 3D rigid registration (linumpy.reference) - #142
Draft
FIrgolitsch wants to merge 1 commit into
Draft
Add Allen RAS+ alignment + 3D rigid registration (linumpy.reference)#142FIrgolitsch wants to merge 1 commit into
FIrgolitsch wants to merge 1 commit into
Conversation
FIrgolitsch
marked this pull request as draft
July 7, 2026 15:16
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Extends
linumpy.reference.allenwith RAS+ alignment of the Allen CCF template and a 3D rigid registration routine that aligns a mouse-brain volume to that template. Adds a full offline test suite (the Allen download is monkey-patched) covering orientation, numpy↔SimpleITK conversion, end-to-end self-registration, and downsampling/cropping behaviour.Land after #141.
What changed
numpy_to_sitk_image(volume, spacing, cast_dtype=None)— converts a(Z, Y, X)numpy array to a SimpleITK image with correct(X, Y, Z)spacing; optional dtype cast without mutating the input.download_template_ras_aligned(resolution, ...)— downloads the Allen average template and reorients it from its native PIR (== Allen-documented "ASL") layout to RAS+ (+X=Right, +Y=Anterior, +Z=Superior) viaPermuteAxes((2,0,1))+ Y/Z flips. The anatomical reasoning (olfactory-bulb / DV-band / ML-symmetry landmarks) is documented inline.register_3d_rigid_to_allen(...)— multi-resolutionEuler3DTransformregistration against the RAS template with several robustness measures:MI/MSE/CC/AntsCC), optional iteration callback, optional initial rotation.download_templatenow usesPath(...).open()+writelines(tqdm(...)).Tests (
test_io_allen.py, new)+X=Right,+Y=Anterior,+Z=Superiorvia per-axis gradient checks; size reflects the permutation.numpy_to_sitk_image— round-trip value/spacing/dtype preservation, input not mutated..data/allen_template_100um.nrrd; locks the PIR/ASL layout and the RAS result against silent upstream changes.Reviewer focus
download_template_ras_aligned) are the scientifically load-bearing part — the inline derivation and the synthetic + real-NRRD landmark tests are the place to confirm correctness.register_3d_rigid_to_allenis long; the highest-risk logic is the centroid re-initialization after resampling and the crop-offset restoration into the SITK(X,Y,Z)translation. Both have explicit tests; worth a close read.How to verify