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

Fibertube Density #1112

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c53817
fibertube density + endpoint scoring. Lacks demo update + tests
VincentBeaud Nov 25, 2024
b09fce3
Merge branch 'tracking_local_custom_seeds' of github.com:VincentBeaud…
VincentBeaud Nov 26, 2024
8573b2d
doc fix
VincentBeaud Nov 28, 2024
34d0dfe
Merge branch 'new_endpoint_scoring' of github.com:VincentBeaud/scilpy…
VincentBeaud Nov 28, 2024
6adb0b4
Merge branch 'tracking_local_custom_seeds' of github.com:VincentBeaud…
VincentBeaud Nov 28, 2024
e0c13a7
Merge branch 'tracking_local_custom_seeds' of github.com:VincentBeaud…
VincentBeaud Nov 28, 2024
0df0aba
Merge branch 'tracking_local_custom_seeds' of github.com:VincentBeaud…
VincentBeaud Nov 28, 2024
650ebac
Fix volumetric density and add collision density
VincentBeaud Nov 28, 2024
7c85e00
Density pep8 and test
VincentBeaud Nov 28, 2024
29c2a0f
minifix
VincentBeaud Nov 29, 2024
b4d77e8
Merge branch 'new_endpoint_scoring' of github.com:VincentBeaud/scilpy…
VincentBeaud Nov 29, 2024
133d870
remove density metric from collision filtering
VincentBeaud Nov 29, 2024
75562d7
Merge branch 'new_endpoint_scoring' of github.com:VincentBeaud/scilpy…
VincentBeaud Nov 29, 2024
b8df660
Remove fibertube density from demo
VincentBeaud Nov 29, 2024
58f7a44
Merge branch 'scilus:master' into dev
VincentBeaud Dec 3, 2024
25d9bd1
Merge branch 'tracking_local_custom_seeds' of github.com:VincentBeaud…
VincentBeaud Dec 11, 2024
b47ae92
Merge branch 'master' of github.com:VincentBeaud/scilpy into dev
VincentBeaud Dec 11, 2024
d51543d
Merge branch 'master' of github.com:VincentBeaud/scilpy into dev
VincentBeaud Dec 17, 2024
ba80d07
doc and test fix
VincentBeaud Dec 17, 2024
33247b4
Merge branch 'master' into dev
VincentBeaud Dec 17, 2024
ac0c4a1
Fix for PR
VincentBeaud Dec 18, 2024
5819f83
Merge branch 'master' into dev
VincentBeaud Dec 18, 2024
6fd2ebe
Allow importing 1 dps value, to be mapped to each streamline.
VincentBeaud Dec 19, 2024
cf1dced
Ad test for last commit feature
VincentBeaud Dec 19, 2024
c1ff5db
Update doc to allow fibertubes with collisions.
VincentBeaud Dec 19, 2024
b46cc83
Merge branch 'scilus:master' into dev
VincentBeaud Jan 14, 2025
9c7b861
Pass single_value as an argument instead of a file - tested + pep8
VincentBeaud Jan 17, 2025
964e629
Merge branch 'master' into dev
VincentBeaud Jan 17, 2025
a1fe3a8
Clarify doc in fibertube_scoring
VincentBeaud Jan 17, 2025
0c0fca2
Merge branch 'dev' of github.com:VincentBeaud/scilpy into dev
VincentBeaud Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions scripts/scil_fibertube_compute_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
3. By doing the same steps for samples that landed within 2 or more
fibertubes, we can create a density map of the fibertube collisions.

To form fibertubes from a set of streamlines, you can use the scripts:
- scil_tractogram_filter_collisions.py to assign a diameter to each streamline
and remove all colliding fibertubes.
- scil_tractogram_dps_math.py to assign a diameter without filtering.

See also:
- docs/source/documentation/fibertube_tracking.rst
"""
Expand Down Expand Up @@ -39,12 +44,8 @@ def _build_arg_parser():

p.add_argument('in_fibertubes',
help='Path to the tractogram (must be .trk) file \n'
'containing fibertubes. They must be: \n'
'1- Void of any collision. \n'
'2- With their respective diameter saved \n'
'as data_per_streamline. \n'
'For both of these requirements, see \n'
'scil_tractogram_filter_collisions.py.')
'containing fibertubes. They must have their \n'
'respective diameter saved as data_per_streamline.')

p.add_argument('--out_density_map', default=None, type=str,
help='Path of the density Nifti image.')
Expand Down
10 changes: 3 additions & 7 deletions scripts/scil_fibertube_score_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,9 @@ def _build_arg_parser():
formatter_class=argparse.RawTextHelpFormatter)

p.add_argument('in_fibertubes',
help='Path to the tractogram file (must be .trk) \n'
'containing ground-truth fibertubes. They must be: \n'
'1- Void of any collision. \n'
'2- With their respective diameter saved \n'
'as data_per_streamline. \n'
'For both of these requirements, see \n'
'scil_tractogram_filter_collisions.')
help='Path to the tractogram (must be .trk) file \n'
'containing fibertubes. They must have their \n'
'respective diameter saved as data_per_streamline.')

p.add_argument('in_tracking',
help='Path to the tractogram file (must be .trk) \n'
Expand Down
13 changes: 7 additions & 6 deletions scripts/scil_fibertube_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

Seeding is done within the first segment of each fibertube.

To form fibertubes from a set of streamlines, you can use the scripts:
- scil_tractogram_filter_collisions.py to assign a diameter to each streamline
and remove all colliding fibertubes.
- scil_tractogram_dps_math.py to assign a diameter without filtering.

For a better understanding of Fibertube Tracking please see:
- docs/source/documentation/fibertube_tracking.rst
"""
Expand Down Expand Up @@ -57,12 +62,8 @@ def _build_arg_parser():

p.add_argument('in_fibertubes',
help='Path to the tractogram (must be .trk) file \n'
'containing fibertubes. They must be: \n'
'1- Void of any collision. \n'
'2- With their respective diameter saved \n'
'as data_per_streamline. \n'
'For both of these requirements, see \n'
'scil_tractogram_filter_collisions.py.')
'containing fibertubes. They must have their \n'
'respective diameter saved as data_per_streamline.')

p.add_argument('out_tractogram',
help='Tractogram output file (must be .trk or .tck).')
Expand Down
38 changes: 26 additions & 12 deletions scripts/scil_tractogram_dps_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ def _build_arg_parser():
'"delete" operations.')

import_args = p.add_argument_group('Operation "import" mandatory options')
import_args.add_argument('--in_dps_file',
import_excl = import_args.add_mutually_exclusive_group()
import_excl.add_argument('--in_dps_file',
help='File containing the data to import to\n'
'streamlines (.txt, .npy or .mat).')
'streamlines (.txt, .npy or .mat). There\n'
'must be the same amount of entries as\n'
'there are streamlines.')
import_excl.add_argument('--in_dps_file_single_value',
VincentBeaud marked this conversation as resolved.
Show resolved Hide resolved
help='File containing a single value to import\n'
'to each streamlines (.txt, .npy or .mat).')

export_args = p.add_argument_group('Operation "export" mandatory options')
export_args.add_argument('--out_dps_file',
Expand Down Expand Up @@ -98,9 +104,15 @@ def main():
sft = load_tractogram_with_reference(parser, args, args.in_tractogram)

if args.operation == 'import':
if args.in_dps_file is None:
parser.error('The --in_dps_file option is required for ' +
'the "import" operation.')
if args.in_dps_file:
dps_file = args.in_dps_file
else:
dps_file = args.in_dps_file_single_value

if dps_file is None:
parser.error('One of --in_dps_file or ' +
'--in_dps_file_single_value is required for the ' +
'"import" operation.')

if args.out_tractogram is None:
parser.error('The --out_tractogram option is required for ' +
Expand All @@ -113,13 +125,15 @@ def main():
' overwriting.'.format(args.dps_key))

# Load data and remove extraneous dimensions
data = np.squeeze(load_matrix_in_any_format(args.in_dps_file))

# Quick check as the built-in error from sft is not too explicit
if len(sft) != data.shape[0]:
raise ValueError('Data must have as many entries ({}) as there are'
' streamlines ({}).'.format(data.shape[0],
len(sft)))
data = np.squeeze(load_matrix_in_any_format(dps_file))

# Validate data shape
if args.in_dps_file and len(sft) != data.shape[0]:
raise ValueError(
'Data must have as many entries ({}) as there are '
'streamlines ({}).'.format(data.shape[0], len(sft)))
if args.in_dps_file_single_value:
data = [data] * len(sft.streamlines)

sft.data_per_streamline[args.dps_key] = data

Expand Down
16 changes: 16 additions & 0 deletions scripts/tests/test_tractogram_dps_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ def test_execution_dps_math_import(script_runner, monkeypatch):
assert ret.success


def test_execution_dps_math_import_single_value(script_runner,
monkeypatch):
monkeypatch.chdir(os.path.expanduser(tmp_dir.name))
in_bundle = os.path.join(SCILPY_HOME, 'filtering',
'bundle_4.trk')
filename = 'vals.npy'
outname = 'out.trk'
np.save(filename, [1.1])
ret = script_runner.run('scil_tractogram_dps_math.py',
in_bundle, 'import', 'key',
'--in_dps_file_single_value', filename,
'--out_tractogram', outname,
'-f')
assert ret.success


def test_execution_dps_math_import_with_missing_vals(script_runner,
monkeypatch):
monkeypatch.chdir(os.path.expanduser(tmp_dir.name))
Expand Down
Loading