Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAR-4932][External] correct pixdim application in mask to polygon #968

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

dorfmanrobert
Copy link
Contributor

@dorfmanrobert dorfmanrobert commented Nov 19, 2024

Problem

When pixdims[0]pixdims[1], 3D mask annotations are incorrectly scaled when imported as polygons from a NifTI file. This is due to applying the pixdims to the incorrect axes.

Solution

The key thing to note is that in the 2D mask slice arrays:

  • rows are indexed top to bottom
  • columns are indexed left to right

But in visualisation space, the columns represent the x axis and the rows represent the y axis, which is why we switch x and y. Now, since the pixdims entries correspond to the axes of visualisation, not array index axes, we need to switch the application of the pixdims.

Changelog

Correct import of 3D NifTI masks to polygons when pixdims vary across axes.

Copy link

linear bot commented Nov 19, 2024

Copy link
Contributor Author

@dorfmanrobert dorfmanrobert Nov 19, 2024

Choose a reason for hiding this comment

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

The pixdims are (0.7986109, 0.798611, 6.0000024), so this test covers the code changes as pixdims[0]!=pixdims[1]. Due to the fix, the expected outputs needed to be recreated.

@@ -376,7 +376,7 @@ def adjust_for_pixdims(x, y, pixdims):
else:
return {"x": y, "y": x}
else:
return {"x": y * pixdims[1], "y": x * pixdims[0]}
return {"x": y * pixdims[0], "y": x * pixdims[1]}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the real change in logic.


data_array = reoriented_img.get_fdata()
pixdims = reoriented_img.header.get_zooms()

Copy link
Contributor Author

@dorfmanrobert dorfmanrobert Nov 19, 2024

Choose a reason for hiding this comment

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

These changes to process_nifti are unrelated and make the function more explicitly able to handle arbitrarily oriented outputs, even though this is not needed for importing to a fixed orientation of LPI.

Before, the pixdims were taken from volume reoriented to RAS, meaning the output orientation needed to be in RAS order as well for the pixdims to be ordered correctly. Now the output's axes can be any order.

@dorfmanrobert dorfmanrobert changed the title [DAR-4932][Internal] correct pixdim application in mask to polygon [DAR-4932][External] correct pixdim application in mask to polygon Nov 19, 2024
@dorfmanrobert dorfmanrobert merged commit f9eed67 into master Nov 19, 2024
20 checks passed
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.

2 participants