scil_tractogram_resample.py

usage: __main__.py [-h] [--never_upsample] [--point_wise_std POINT_WISE_STD]
                   [--tube_radius TUBE_RADIUS] [--gaussian SIGMA]
                   [-e ERROR_RATE] [--keep_invalid_streamlines]
                   [--downsample_per_cluster]
                   [--qbx_thresholds QBX_THRESHOLDS [QBX_THRESHOLDS ...]]
                   [--seed SEED] [--reference REFERENCE]
                   [-v [{DEBUG,INFO,WARNING}]] [-f]
                   in_tractogram nb_streamlines out_tractogram

Script to resample a tractogram to a set number of streamlines.
Default behavior:
- IF number of requested streamlines is lower than streamline count: DOWNSAMPLE
- IF number of requested streamlines is higher than streamline count: UPSAMPLE
To prevent upsample if not desired use --never_upsample.

Can be useful to build training sets for machine learning algorithms, to
upsample under-represented bundles or downsample over-represented bundles.

Works by either selecting a subset of streamlines or by generating new
streamlines by adding gaussian noise to existing ones.

Upsampling:
    Includes smoothing to compensate for the noisiness of new streamlines
    generated by the process.
Downsampling:
    Includes the possibility of choosing randomly *per Quickbundle cluster* to
    ensure that all clusters are represented in the final tractogram.

Example usage:
$ scil_tractogram_resample.py input.trk 1000 output.trk --point_wise_std 0.5 --gaussian 5 --keep_invalid_streamlines
$ scil_visualize_bundles.py output.trk --local_coloring --width=0.1

positional arguments:
  in_tractogram         Input tractography file.
  nb_streamlines        Number of streamlines to resample the tractogram to.
  out_tractogram        Output tractography file.

options:
  -h, --help            show this help message and exit
  --never_upsample      Make sure to never upsample a tractogram.
                        Useful when downsample batch of files using bash.
  --seed SEED           Use a specific random seed for the resampling.
  --reference REFERENCE
                        Reference anatomy for tck/vtk/fib/dpy file
                        support (.nii or .nii.gz).
  -v [{DEBUG,INFO,WARNING}]
                        Produces verbose output depending on the provided level.
                        Default level is warning, default when using -v is info.
  -f                    Force overwriting of the output files.

Upsampling params:
  --point_wise_std POINT_WISE_STD
                        Noise to add to existing streamlines points to generate new ones [1].
  --tube_radius TUBE_RADIUS
                        Maximum distance to generate streamlines around the original ones [1].
  --gaussian SIGMA      Sigma for smoothing. Use the value of surrounding X,Y,Z points on the streamline to blur the streamlines.
                        A good sigma choice would be around 5.
  -e ERROR_RATE         Maximum compression distance in mm [0.1].
  --keep_invalid_streamlines
                        Keep invalid newly generated streamlines that may go out of the
                        bounding box.

Downsampling params:
  --downsample_per_cluster
                        If set, downsampling will be done per cluster (computed with
                        Quickbundles) to ensure that at least some streamlines are
                        kept per bundle. Else, random downsampling is performed (default).
  --qbx_thresholds QBX_THRESHOLDS [QBX_THRESHOLDS ...]
                        If you chose option '--downsample_per_cluster', you may set
                        the QBx threshold value(s) here. Default: [40, 30, 20]