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

Tractogram scripts part7: segmentation scripts #993

Merged
merged 12 commits into from
Jun 18, 2024

Conversation

EmmaRenauld
Copy link
Contributor

@EmmaRenauld EmmaRenauld commented May 22, 2024

Quick description

The four segmentation scripts. (Renaming = made changes in many files). Improved doc everywhere to reference each other.

  1. scil_tractogram_segment_bundles_with_bundleseg.py:

    • Was ok! Clarified verifications.
  2. scil_tractogram_segment_connections_from_labels.py:

    • A lot of the lines have changed because I moved most of the processing to scilpy.tractanalysis.connectivity_segmentation! Will be difficult to review, sorry.
    • Added an option to save the final streamlines in out_dir. Previously, they were saved as soon as you added option --out_dir.
    • Added a lot of prints at debug level.
    • Only saving intermediate files if that step was processed.
    • Reusing the same variable (current_sft) rather than a separate sft name at each step to avoid multiplying data in memory. Using current_sft.streamlines rather than a separate streamlines = current_sft.streamlines, for the same reason.
    • Separating the method remove_loops_and_sharp_turns into two: remove_loops, remove_sharp turns for more clarification; the "remove_loops" part was used twice (option args.loop_max_angle), once at the remove loops step, once at the remove_sharp_turn steps. Unnecessary processing removed.
    • Encapsulating the "remove overlapping points" section in scilpy.tractograms.streamline_operations
    • Using the existing function "filter_streamlines_by_length" rather than the local _prune_length method.
  3. scil_tractogram_tractogram_segment_with_recobundles.py:

    • Fixed the verbose. Still had a if args.verbose.
    • Explained more the space and origin management. Added a to_rasmm, to_center to clarify, but it's the default when loading.
    • Used new scilpy's save_tractogram, that checks if empty first.
  4. scil_tractogram_tractogram_segment_with_ROI_and_score.py:

    • Considering that I already have a 30-script PR, let's do it in another PR!!

Type of change

Check the relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@pep8speaks
Copy link

pep8speaks commented May 22, 2024

Hello @EmmaRenauld, Thank you for updating !

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-05-31 00:18:40 UTC

@EmmaRenauld EmmaRenauld changed the title [WIP] Tractogram scripts part7: segmentation scripts Tractogram scripts part7: segmentation scripts May 22, 2024
Copy link

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 79.34509% with 82 lines in your changes are missing coverage. Please review.

Project coverage is 68.23%. Comparing base (17b9a4a) to head (dd02451).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #993      +/-   ##
==========================================
+ Coverage   68.14%   68.23%   +0.09%     
==========================================
  Files         419      419              
  Lines       21369    21388      +19     
  Branches     3216     3206      -10     
==========================================
+ Hits        14561    14594      +33     
+ Misses       5533     5527       -6     
+ Partials     1275     1267       -8     
Components Coverage Δ
Scripts 69.19% <78.24%> (+0.05%) ⬆️
Library 66.85% <80.66%> (+0.18%) ⬆️

Copy link
Contributor

@karanphil karanphil left a comment

Choose a reason for hiding this comment

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

Looks good from my limited knowledge of these scripts! Only a small comment. Also, do you know why Github doesn't understand some of the scripts that were simply renamed, instead of thinking you deleted/added a file...

scilpy/tractanalysis/bundle_operations.py Outdated Show resolved Hide resolved
Copy link
Contributor

@arnaudbore arnaudbore left a comment

Choose a reason for hiding this comment

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

A couple of questions for this review.

scilpy/tractograms/streamline_and_mask_operations.py Outdated Show resolved Hide resolved
scilpy/tractograms/streamline_and_mask_operations.py Outdated Show resolved Hide resolved
scripts/scil_tractogram_segment_with_recobundles.py Outdated Show resolved Hide resolved
formatter_class=argparse.RawTextHelpFormatter,
description=__doc__)
p.add_argument('in_tractograms', nargs='+',
help='Tractogram filename (s). Format must be one of \n'
Copy link
Contributor

Choose a reason for hiding this comment

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

do we keep saying trk, tck, fib, vtk ...

Copy link
Contributor Author

@EmmaRenauld EmmaRenauld May 31, 2024

Choose a reason for hiding this comment

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

I agree, it's heavy. Could belong in a PR removing it everywhere.

remove_loops = not args.no_remove_loops
remove_outliers = not args.no_remove_outliers
remove_curv_dev = not args.no_remove_curv_dev
construct_hdf5_from_connectivity(
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure @frheault can answer this question but why so much post processing here instead of using already cleaned tractograms ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered the same. We are writing in our draft scilpy paper that we DON'T do that, and people can combine scripts themselves.

Copy link
Member

@frheault frheault May 31, 2024

Choose a reason for hiding this comment

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

It is because each time you clean a tractogram with one script you save a copy of the tractogram and you save it on IO, so it is often required to do it all at once for key steps in the pipeline.

Also, since 30-40% of streamlines don't even touch the labels, you save some processing by computing these on a filtered tractogram (touching labels). Outliers removal is bundle-based, so it has to happen while segmenting (we cant save 10 000 TRK to run 10 000 outliers removal)

We have the scripts to do it yourself and turn it off if you want. But if you wanted to avoid doing inside the script you would have to:
binarize the labels, remove all streamlines not touching the labels (to save 30-40% of computation for loop), run remove loop, then run that script.
Then run that script, it not that complex, but its a function call and 1-2 parameters in that script, so I am not sure if it is worth it to remove it

PS: This script also cut streamline if entering/exiting gray matter multiple time, so this affect the results of postprocessing (because we change the streamline during the script.

Copy link
Contributor

@arnaudbore arnaudbore May 31, 2024

Choose a reason for hiding this comment

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

Would it make sense to have enough information to be able to replicate the preproc of this script and to do it outside of the script if the user wants and then use it without any preproc ? @frheault

Copy link
Member

Choose a reason for hiding this comment

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

That would require 3-4 scripts to either support .h5 as input and output or to duplicate scripts (one version for trk/tck and one for h5).

That's a complexity that is not so worth it I think.

Copy link
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

I don't know much about segmentation script but I scrolled through the code and, as far as I'm concerned, it seems alright.

@arnaudbore arnaudbore merged commit 070d713 into scilus:master Jun 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants