Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid streamlines (out of bbox) #42

Merged
merged 5 commits into from Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably go in scilpy.io.streamlines.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamlines -> streamline

"""


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()