Align imaging orientation to Allen RAS+ + transform helpers + viz contrast fix - #141
Draft
FIrgolitsch wants to merge 1 commit into
Draft
Align imaging orientation to Allen RAS+ + transform helpers + viz contrast fix#141FIrgolitsch 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.imagingto align 3D volumes to the Allen RAS+ template convention, and fixes contrast scaling in the orthogonal-view renderers. Changes the orientation target from(S, R, A)to(S, A, R)so a reoriented volume feeds directly intonumpy_to_sitk_imageas a SITK image ordered(X=R, Y=A, Z=S)— matching the Allen template and avoiding a spurious 90° rotation that the rigid registration was failing to recover.Land after #140.
What changed
orientation.py— convention change.parse_orientation_codenow targets(S, A, R)instead of(S, R, A). Theletter_mapand all docstring/examples are updated. This changes the permutation/flip output for every input code, so any caller caching or asserting on a specific permutation needs updating.orientation.py— new helpers for downstream RAS alignment:sitk_transform_to_affine_matrix— Euler3D / AffineTransform → 4×4 matrix in(Z, Y, X)OME-NGFF ordering.store_transform_in_metadata— writes that affine as an OME-ZarrcoordinateTransformationsblock.compute_centered_reference_and_transform— builds a zero-origin reference grid and the composite transform for resampling a moving image into it.visualization.py— contrast fix. Orthogonal and annotated views now compute a per-panelvmaxfrom positive, finite voxels only (percentile) and clampvmin = 0, instead of a single global min/percentile over all panels. Fixes washed-out previews when one panel is dominated by zero/negative background.test_imaging_orientation.pyre-targeted to the(S, A, R)convention (identity is nowSAR,PIR/RAS/LPSexpectations updated). Newtest_imaging_orientation_ras.pycovers the three new helpers (identity/translation permutation, brain-volume preservation under rotation, affine-block round-trip into.zattrs).Reviewer focus
register_3d_rigid_to_allen(next PR). The rationale is in the module docstring; the updatedPIR/RAS/LPStest expectations are the best place to confirm the new mapping is correct.compute_centered_reference_and_transformderives the output grid size from the transformed corner points — verify the rounding (np.ceil) matches how downstream resamplers consume it.store_transform_in_metadataprepends an affine to each dataset's existingcoordinateTransformations; check the ordering is right for your reader.How to verify