[BUG]: Coordinates transforms to native space using ANTs are off #388

Merged
synchon merged 5 commits from fix/coords-ants into main 2024-11-19 12:25:12 +00:00
3 changed files with 15 additions and 4 deletions

View file

@ -0,0 +1 @@
Fix coordinates space transformation using ANTs by `Synchon Mandal`_

View file

@ -55,19 +55,24 @@ class ANTsCoordinatesWarper:
# Save existing coordinates to a tempfile
pretransform_coordinates_path = (
element_tempdir / "pretransform_coordinates.txt"
element_tempdir / "pretransform_coordinates.csv"
)
fraimondo commented 2024-11-18 19:44:14 +00:00 (Migrated from github.com)

can we just do x[0] *= -1... It's more easy to read than a lambda function to multiply two axis by -1 and another axis by 1.

can we just do `x[0] *= -1`... It's more easy to read than a lambda function to multiply two axis by -1 and another axis by 1.
synchon commented 2024-11-19 10:06:24 +00:00 (Migrated from github.com)

Not sure I follow, could you please show what L63 should be?

Not sure I follow, could you please show what L63 should be?
fraimondo commented 2024-11-19 11:29:55 +00:00 (Migrated from github.com)

before L60

# Convert LPS to RAS
seeds[:, 0] *= -1
seeds[:, 1] *= -1
before L60 ```python # Convert LPS to RAS seeds[:, 0] *= -1 seeds[:, 1] *= -1 ```
# 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 = [
@ -86,9 +91,14 @@ class ANTsCoordinatesWarper:
)
# 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

View file

@ -362,7 +362,7 @@ class CoordinatesRegistry(BasePipelineDataRegistry, metaclass=Singleton):
seeds = ANTsCoordinatesWarper().warp(
seeds=seeds,
target_data=target_data,
warp_data=warper_spec,
warp_data=inverse_warper_spec,
)
return seeds, labels