WIP: ENH: Add order-explicit spatial keys to the Python image dict protocol - #6710
Draft
hjmjohnson wants to merge 1 commit into
Draft
WIP: ENH: Add order-explicit spatial keys to the Python image dict protocol#6710hjmjohnson wants to merge 1 commit into
hjmjohnson wants to merge 1 commit into
Conversation
Add 'origin', 'spacing', 'direction', 'index', and 'size' keys with explicit '_xyz' (ITK order) and '_zyx' (NumPy order) suffixes to itk.Image __getitem__/__setitem__/keys, and deprecate the bare order-ambiguous 'origin'/'spacing'/'direction' keys, which return (z,y,x) order in ITK but (x,y,z) order in SimpleITK (issue InsightSoftwareConsortium#6706). Writing 'index'/'size' keys goes through SetRegions. Bare-key access warns with DeprecationWarning, escalated to FutureWarning when configured with ITK_FUTURE_LEGACY_REMOVE (itkConfig.FutureLegacyRemove, env-overridable). A migration guide documents the protocol. The test verifies both frames against the C++ oracles TransformContinuousIndexToPhysicalPoint and TransformPhysicalPointToContinuousIndex, including non-zero start index, to 1e-12.
Member
Author
|
@thewtex @blowekamp This WIP is a proposal to resolve the ITK/SimpleITK/numpy interoperability inconsistencies. I've marked this as a WIP for discussion purposes. Feel free to criticize, update, adapt, or adopt whatever you think is useful. |
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.
Adds order-explicit spatial keys (
origin|spacing|direction|index|size×_xyz|_zyx) to theitk.Imagedict interface and deprecates the order-ambiguous bare keys, resolving the ITK↔SimpleITK convention conflict that blocks #6021. Fixes #6706. Companion SimpleITK WIP: SimpleITK/SimpleITK#2655 — both PRs implement the identical protocol so generic code works across toolkits.Design summary
image['spacing']returns (z,y,x) in ITK but (x,y,z) in SimpleITK — same key, opposite conventions, silent geometry corruption for generic consumers (Python image['spacing'] axis-order conflict between ITK (z,y,x) and SimpleITK (x,y,z) blocks generic interop (PR #6021) #6706).p = origin + direction @ (spacing * i)and its inverse reproduceTransformContinuousIndexToPhysicalPoint/TransformPhysicalPointToContinuousIndexto ≤3e-14 in either convention, including non-zero start index (index_*keys — absent from the old interface, causing 26 mm placement error in the test geometry).direction_zyx = np.flip(D, axis=None)= P·D·P preserves composition/inversion; the SimpleITK counterparttuple(reversed(flat_direction))is bit-identical.index_*/size_*goes throughSetRegions().DeprecationWarning;ITK_FUTURE_LEGACY_REMOVE=ON(or envITK_PYTHON_FUTURE_LEGACY_REMOVE) escalates to always-visibleFutureWarningvia newitkConfig.FutureLegacyRemove.Documentation/docs/migration_guides/.Testing
PythonGeometryProtocolTest: both-domain forward/inverse vs C++ oracles, homomorphism identities, setter round-trips, warning category assertions, SetRegions-backed writes with reallocation.PythonExtrasTest(bare-key consumers,dict(image), serialization) unchanged and passing.WIP pending: design sign-off on key naming (@thewtex @blowekamp @dzenanz), coordination with the SimpleITK companion, and whether
keys()should stop listing the bare three underITK_FUTURE_LEGACY_REMOVE.