Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

ITK uses x,y,z coordinate order while napari uses z,y,x (row-major NumPy). The point conversion functions now handle this automatically via a reverse_coords kwarg, enabled by default.

Changes

  • points_layer_from_point_set: Added reverse_coords=True kwarg to reverse ITK (x,y,z) → napari (z,y,x)
  • point_set_from_points_layer: Added reverse_coords=True kwarg to reverse napari (z,y,x) → ITK (x,y,z)
  • Updated existing tests to expect reversed coordinates by default
  • Added tests for reverse_coords=False, roundtrip conversions, and 2D points

Usage

from itk_napari_conversion import points_layer_from_point_set, point_set_from_points_layer

# Default behavior: coordinates are reversed automatically
points_layer = points_layer_from_point_set(itk_point_set)  # x,y,z → z,y,x
point_set = point_set_from_points_layer(napari_layer)      # z,y,x → x,y,z

# Opt out if needed
points_layer = points_layer_from_point_set(itk_point_set, reverse_coords=False)
Original prompt

Per:

Create a pull request that changes the order of points from x,y,z to z,y,z or the inverse, as appropriate, in points_layer_from_point_set, point_set_from_points_layer. Make the behavior a boolean kwarg, but enable by default. Add tests.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update points order in points_layer_from_point_set Add reverse_coords option to point conversion functions Dec 5, 2025
Copilot AI requested a review from thewtex December 5, 2025 21:00
Copy link

@N-Dekker N-Dekker Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for fixing the order of point coordinates, @thewtex

I find some parts of this pull request (adjusting ".gitignore" and adding/removing binaries for Python 3.12) hard to review. Are they essential for the "reverse_coords" fix? If so, can you place them in a separate commit? If they are unrelated, please move them into a separate pull request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker I'll get this published soon to ease your application in elastix-napari.

I've cleaned up the history and added the .gitignore changes to a new PR.

Comment on lines -74 to +92
data = points_array
if reverse_coords:
# Reverse coordinate order from ITK (x,y,z) to napari (z,y,x)
data = points_array[:, ::-1]
else:
data = points_array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main part of the fix, right? Cool! I can't wait to try it out, with SuperElastix/elastix-napari#65 😃

Comment on lines +157 to +159
if reverse_coords:
# Reverse coordinate order from napari (z,y,x) to ITK (x,y,z)
data = data[:, ::-1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, the other "main" part of the fix 😃

@N-Dekker
Copy link

N-Dekker commented Dec 8, 2025

@thewtex For my understanding, is this proposed new reverse_coords argument intended to be a permanent feature, or is it meant as a workaround?

In practice, shouldn't the coordinates always be reverted anyway, when converting between a napari Points layer and an itk.PointSet?

- Add reverse_coords boolean kwarg (default True) to points_layer_from_point_set
- Add reverse_coords boolean kwarg (default True) to point_set_from_points_layer
- When enabled, converts between ITK's x,y,z order and napari's z,y,x order
- Update existing tests to account for new default behavior
- Add tests for reverse_coords=False, roundtrip, and 2D points

Co-authored-by: thewtex <[email protected]>
@thewtex thewtex force-pushed the copilot/change-points-order branch from a051f95 to d5e5a73 Compare December 8, 2025 19:47
@thewtex
Copy link
Member

thewtex commented Dec 8, 2025

@thewtex For my understanding, is this proposed new reverse_coords argument intended to be a permanent feature, or is it meant as a workaround?

In practice, shouldn't the coordinates always be reverted anyway, when converting between a napari Points layer and an itk.PointSet?

@N-Dekker yes, it will be permanent. It is left as an option in case the client calling the function already made the change (using with a different library, etc.) to avoid the need and performance hit for doing it again.

@thewtex thewtex merged commit 70c2772 into main Dec 8, 2025
13 checks passed
@thewtex thewtex deleted the copilot/change-points-order branch December 8, 2025 20:05
@thewtex
Copy link
Member

thewtex commented Dec 8, 2025

@N-Dekker published to PyPI as version 0.5.1

N-Dekker added a commit to SuperElastix/elastix-napari that referenced this pull request Dec 9, 2025
N-Dekker added a commit to SuperElastix/elastix-napari that referenced this pull request Dec 9, 2025
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.

3 participants