Skip to content

Commit

Permalink
Merge pull request #388 from juaml/fix/coords-ants
Browse files Browse the repository at this point in the history
[BUG]: Coordinates transforms to native space using `ANTs` are off
  • Loading branch information
synchon authored Nov 19, 2024
2 parents 93ed07a + 0163c02 commit 3a05a93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/388.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix coordinates space transformation using ANTs by `Synchon Mandal`_
16 changes: 13 additions & 3 deletions junifer/data/coordinates/_ants_coordinates_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,24 @@ def warp(

# Save existing coordinates to a tempfile
pretransform_coordinates_path = (
element_tempdir / "pretransform_coordinates.txt"
element_tempdir / "pretransform_coordinates.csv"
)
# Convert LPS to RAS
seeds[:, 0] *= -1
seeds[:, 1] *= -1
np.savetxt(
pretransform_coordinates_path,
seeds,
delimiter=",",
# Add header while saving to make ANTs work
header="x,y,z",
# Remove comment tag for header
comments="",
)

# Create a tempfile for transformed coordinates output
transformed_coords_path = (
element_tempdir / "coordinates_transformed.txt"
element_tempdir / "coordinates_transformed.csv"
)
# Set antsApplyTransformsToPoints command
apply_transforms_to_points_cmd = [
Expand All @@ -86,9 +91,14 @@ def warp(
)

# Load coordinates
return np.loadtxt(
transformed_seeds = np.loadtxt(
# Skip header when reading
transformed_coords_path,
delimiter=",",
skiprows=1,
)
# Convert RAS to LPS
transformed_seeds[:, 0] *= -1
transformed_seeds[:, 1] *= -1

return transformed_seeds
2 changes: 1 addition & 1 deletion junifer/data/coordinates/_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def get(
seeds = ANTsCoordinatesWarper().warp(
seeds=seeds,
target_data=target_data,
warp_data=warper_spec,
warp_data=inverse_warper_spec,
)

return seeds, labels

0 comments on commit 3a05a93

Please sign in to comment.