Skip to content

Align imaging orientation to Allen RAS+ + transform helpers + viz contrast fix - #141

Draft
FIrgolitsch wants to merge 1 commit into
linum-uqam:mainfrom
FIrgolitsch:pr-imaging
Draft

Align imaging orientation to Allen RAS+ + transform helpers + viz contrast fix#141
FIrgolitsch wants to merge 1 commit into
linum-uqam:mainfrom
FIrgolitsch:pr-imaging

Conversation

@FIrgolitsch

@FIrgolitsch FIrgolitsch commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends linumpy.imaging to 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 into numpy_to_sitk_image as 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_code now targets (S, A, R) instead of (S, R, A). The letter_map and 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-Zarr coordinateTransformations block.
    • 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-panel vmax from positive, finite voxels only (percentile) and clamp vmin = 0, instead of a single global min/percentile over all panels. Fixes washed-out previews when one panel is dominated by zero/negative background.
  • Tests. test_imaging_orientation.py re-targeted to the (S, A, R) convention (identity is now SAR, PIR/RAS/LPS expectations updated). New test_imaging_orientation_ras.py covers the three new helpers (identity/translation permutation, brain-volume preservation under rotation, affine-block round-trip into .zattrs).

Reviewer focus

  • The convention change is load-bearing and subtle. It exists so the output matches the Allen template handed to register_3d_rigid_to_allen (next PR). The rationale is in the module docstring; the updated PIR/RAS/LPS test expectations are the best place to confirm the new mapping is correct.
  • compute_centered_reference_and_transform derives the output grid size from the transformed corner points — verify the rounding (np.ceil) matches how downstream resamplers consume it.
  • store_transform_in_metadata prepends an affine to each dataset's existing coordinateTransformations; check the ordering is right for your reader.

How to verify

uv run ruff check linumpy/imaging/
uv run ty check linumpy/imaging/
uv run pytest linumpy/tests/test_imaging_orientation.py linumpy/tests/test_imaging_orientation_ras.py -x -v

@FIrgolitsch
FIrgolitsch requested a review from joe-from-mtl as a code owner July 7, 2026 14:58
@FIrgolitsch
FIrgolitsch marked this pull request as draft July 7, 2026 15:16
@FIrgolitsch FIrgolitsch changed the title Rebuild linumpy.imaging (orientation, visualization + tests) Align imaging orientation to Allen RAS+ + transform helpers + viz contrast fix Jul 8, 2026
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