Skip to content

Replace fslmaths calls with nibabel + numpy/scipy #286

@nx10

Description

@nx10

All 8 fslmaths calls and 1 3dcalc call in the codebase are simple voxelwise or morphological operations that can be done with nibabel + numpy/scipy, removing container calls entirely.

functional/masking.py (6 calls)

In bold_masking(), the entire mask refinement chain is fslmaths:

  1. thr + bin — threshold warped probseg at 0.85, binarize
  2. kernel_sphere + dil_f — dilate binary mask by 3mm sphere
  3. kernel_sphere + dil_f — dilate BET mask by 6mm sphere
  4. mas — apply dilated BET mask to bias-corrected BOLD ref
  5. mul — intersect BET mask with AFNI automask
  6. mas — apply final mask to unifized image

All of these are one-liners with numpy (>, *, astype) or scipy (binary_dilation with ball). We already use binary_erosion in distortion.py for the same kind of thing.

anatomical/segmentation.py (2 calls)

  1. thr + bin in fsl_tissue_masks() — threshold FAST PVE at 0.95, binarize
  2. thr + uthr + bin in fsl_wm_bbr_mask() — band-threshold FAST pveseg [2.5, 3.5], binarize

Same story, pure numpy.

functional/initialization.py (1 call)

  1. 3dcalc in truncate_trs() — selects a[start_tr..$] with expression a. Just img.slicer[..., start_tr:] in nibabel.

Why bother

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions