Skip to content

Commit

Permalink
Merge pull request #15 from chiuhoward/main
Browse files Browse the repository at this point in the history
[ENH] Update segmentation.py
  • Loading branch information
arokem authored Nov 13, 2024
2 parents a438f80 + ef436f1 commit bb622a6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions AFQ/tasks/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
from dipy.stats.analysis import afq_profile
from dipy.tracking.streamline import set_number_of_points, values_from_volume

import gzip
import shutil
import os.path as op
from tempfile import mkdtemp

logger = logging.getLogger('AFQ')

Expand Down Expand Up @@ -61,6 +65,19 @@ def segment(data_imap, mapping_imap,
trx = load_trx(streamlines, data_imap["dwi"])
trx.streamlines._data = trx.streamlines._data.astype(np.float32)
tg = trx.to_sft()
elif streamlines.endswith(".tck.gz"):
# uncompress tck.gz to a temporary tck:
temp_tck = op.join(mkdtemp(), op.split(streamlines.replace(".gz", ""))[1])
logger.info(f"Temporary tck file created at: {temp_tck}")
with gzip.open(streamlines, 'rb') as f_in:
with open(temp_tck, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
# initialize stateful tractogram from tck file:
tg = load_tractogram(
temp_tck, data_imap["dwi"], Space.VOX,
bbox_valid_check=False)
is_trx = False


indices_to_remove, _ = tg.remove_invalid_streamlines()
if len(indices_to_remove) > 0:
Expand Down

0 comments on commit bb622a6

Please sign in to comment.