Skip to content

Commit

Permalink
[FIX] fix cross_midline when R/L axis not first orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
36000 committed Nov 12, 2024
1 parent 1bbfc68 commit 146f31b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions AFQ/recognition/other_bundles.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import numpy as np
import logging

import dipy.tracking.utils as dtu
import dipy.tracking.streamline as dts

from scipy.spatial.distance import cdist
logger = logging.getLogger('AFQ')


def clean_by_other_density_map(this_bundle_sls, other_bundle_sls,
Expand Down Expand Up @@ -98,6 +100,10 @@ def clean_relative_to_other_core(core, this_fgarray, other_fgarray, affine):
>>> cleaned_streamlines = [s for i, s in enumerate(streamlines1)
... if cleaned_core_idx[i]]
"""
if len(other_fgarray) == 0:
logger.warning("Cleaning relative to core skipped, no core found.")
return np.ones(this_fgarray.shape[0], dtype=np.bool8)

if core == 'anterior':
core_axis, core_direc = 1, -1
elif core == 'posterior':
Expand Down
12 changes: 10 additions & 2 deletions AFQ/recognition/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import nibabel as nib
import pimms
from time import time
import logging
Expand Down Expand Up @@ -55,9 +56,16 @@ def crosses(fgarray, img):
zero_coord = np.dot(np.linalg.inv(img.affine),
np.array([0, 0, 0, 1]))

orientation = nib.orientations.aff2axcodes(img.affine)
lr_axis = 0
for idx, axis_label in enumerate(orientation):
if axis_label in ['L', 'R']:
lr_axis = idx
break

return np.logical_and(
np.any(fgarray[:, :, 0] > zero_coord[0], axis=1),
np.any(fgarray[:, :, 0] < zero_coord[0], axis=1))
np.any(fgarray[:, :, lr_axis] > zero_coord[lr_axis], axis=1),
np.any(fgarray[:, :, lr_axis] < zero_coord[lr_axis], axis=1))


# Things that can be calculated for multiple bundles at once
Expand Down

0 comments on commit 146f31b

Please sign in to comment.