Skip to content

Commit

Permalink
Merge pull request #42 from frheault/remove_invalid_streamlines
Browse files Browse the repository at this point in the history
Remove invalid streamlines (out of bbox)
  • Loading branch information
arnaudbore committed Sep 17, 2019
2 parents 3564bd1 + 71cc910 commit e10d887
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scilpy/io/utils.py
Expand Up @@ -23,7 +23,8 @@ def load_tractogram_with_reference(parser, args, filepath,
bbox_check=True):
_, ext = os.path.splitext(filepath)
if ext == '.trk':
sft = load_tractogram(filepath, 'same')
sft = load_tractogram(filepath, 'same',
bbox_valid_check=bbox_check)
elif ext in ['.tck', '.fib', '.vtk', '.dpy']:
if args.reference is None:
parser.error('--reference is required for this file format '
Expand Down
52 changes: 52 additions & 0 deletions scripts/scil_remove_invalid_streamlines.py
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse

from dipy.io.streamline import save_tractogram

from scilpy.io.utils import (add_overwrite_arg, add_reference,
assert_inputs_exist, assert_outputs_exist,
load_tractogram_with_reference)

DESCRIPTION = """
Removal of streamlines that are out of the volume bounding box. In voxel space
no negative coordinate and no above volume dimension coordinate are possible.
Any streamlines that do not respect these two conditions are removed.
"""


def _build_args_parser():
p = argparse.ArgumentParser(description=DESCRIPTION,
formatter_class=argparse.RawTextHelpFormatter)

p.add_argument('in_tractogram', metavar='IN_TRACTOGRAM',
help='Tractogram filename. Format must be one of \n'
'trk, tck, vtk, fib, dpy.')

p.add_argument('output_name', metavar='OUTPUT_NAME',
help='Output filename. Format must be one of \n'
'trk, tck, vtk, fib, dpy.')

add_reference(p)

add_overwrite_arg(p)

return p


def main():
parser = _build_args_parser()
args = parser.parse_args()

assert_inputs_exist(parser, args.in_tractogram, args.reference)
assert_outputs_exist(parser, args, args.output_name)

sft = load_tractogram_with_reference(parser, args, args.in_tractogram,
bbox_check=False)
sft.remove_invalid_streamlines()
save_tractogram(sft, args.output_name)


if __name__ == "__main__":
main()

0 comments on commit e10d887

Please sign in to comment.