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

dwi2mask overhaul (replacement PR) #2197

Merged
merged 107 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
282e717
dwi2mask initial overhaul
wtsyeda Jun 16, 2020
2fa4e48
changes description and authorship information
wtsyeda Jun 16, 2020
605f47c
Cleanup of initial dwi2mask Python port
Lestropie Jun 16, 2020
90477ad
Merge pull request #1 from Lestropie/dwi2mask_initialcode
Lestropie Jun 16, 2020
d5840a2
dwi2mask fslbet: Preserve input DWI strides
Lestropie Jun 16, 2020
37f91c2
dwi2mask: Initial addition of new algorithms
Lestropie Jun 16, 2020
f241d49
dwi2mask legacy: Fix divergences from legacy C++ code
Lestropie Jun 17, 2020
90f4476
dwi2mask legacy: Exclude invalid DWI voxels from mask
Lestropie Jun 17, 2020
e374e70
Remove unused file core/filter/dwi_brain_mask.h
Lestropie Jun 17, 2020
19f860c
dwi2mask hdbet: Fix exception name
Lestropie Jun 17, 2020
104ad85
dwi2mask template: Changes from initial testing
Lestropie Jun 17, 2020
e18ed97
dwi2mask template: Fix ANTs call with -nocleanup
Lestropie Jun 17, 2020
0122178
File to execute AFNI 3dautomask algorithm
RicardoRios46 Jun 17, 2020
b04d3ee
dwi2mask template: Fixes to ANTs registration
Lestropie Jun 17, 2020
ce58233
dwi2mask template: Fixes for FSL-based registration
Lestropie Jun 17, 2020
33dbc15
Merge pull request #2 from Lestropie/dwi2mask_rob_updates_day1
Lestropie Jun 17, 2020
83ff548
Generate documentation for dwi2mask port
Lestropie Jun 17, 2020
e9acf83
dwi2mask legacy: Fix missing function
Lestropie Jun 17, 2020
f2d8e1d
dwi2mask: Two separate ANTs interfaces
Lestropie Jun 17, 2020
8bd8f42
dwi2mask hdbet: Fix non-ASCII character in citation
Lestropie Jun 17, 2020
11a9979
dwi2mask ants: Fix binary command check
Lestropie Jun 17, 2020
2e4675a
Added autorship
RicardoRios46 Jun 18, 2020
1400a9f
dwi2mask template: Variable name fix to dwi2mask ants changes
Lestropie Jun 18, 2020
2b27abe
Added and testet -clfrac and -nograd optional commands
RicardoRios46 Jun 18, 2020
9b250c5
Merge pull request #6 from Lestropie/dwi2mask_ants
Lestropie Jun 18, 2020
4a54391
dwi2mask: Update documentation for ants algorithm
Lestropie Jun 18, 2020
e664594
Added the rest of the AFNI parameters. Looks fine but they need more …
RicardoRios46 Jun 18, 2020
1998d2c
Citing original AFNI paper.
RicardoRios46 Jun 18, 2020
1b4eb1e
Added some missing lines to execute optional parameters.
RicardoRios46 Jun 18, 2020
0b1e437
dwi2mask: Fixes for pylint
Lestropie Jun 18, 2020
86727ba
dwi2mask template: Tweak handling of ANTs command paths
Lestropie Jun 18, 2020
a8e10eb
dwi2mask: Refactor image input & output
Lestropie Jun 18, 2020
f75cc56
Merge pull request #7 from Lestropie/dwi2mask_refactor_output
Lestropie Jun 18, 2020
7002bca
dwi2mask: New algorithm "consensus"
Lestropie Jun 18, 2020
9a31f4e
Merge pull request #8 from Lestropie/dwi2mask_consensus
Lestropie Jun 18, 2020
90fa50f
added exvivo algorithm for brain masking
wtsyeda Jun 18, 2020
cf606f9
Changes as suggested in dwi2mask: New algorithm "exvivo" #9
wtsyeda Jun 18, 2020
ff73913
Adressed github comments: Spacing is better in strings. Int paremeters.
RicardoRios46 Jun 18, 2020
e66b665
Merge branch 'dwi2mask' into 3dAutomask
Lestropie Jun 18, 2020
57a9803
Some modification according to dwi2mask: New algorithm "exvivo" #9
wtsyeda Jun 18, 2020
3cd8794
dwi2mask 3dautomask: Code cleanup and resolution with #7
Lestropie Jun 18, 2020
efc04c4
Merge pull request #3 from Lestropie/3dAutomask
Lestropie Jun 18, 2020
17d1bb9
Added progress bar for per-shell histogram matching
wtsyeda Jun 18, 2020
1c9a4c6
Improvements in the code accorind to dwi2mask: New algorithm "trace" #9
wtsyeda Jun 18, 2020
35040f5
execute() function to return string containing the name of the derive…
wtsyeda Jun 18, 2020
e4a8b74
Merge branch 'dwi2mask' into dwi2mask_warda_updates_day3
Lestropie Jun 18, 2020
46c0829
Merge branch 'dwi2mask_warda_updates_day3' of github.com:Lestropie/mr…
Lestropie Jun 18, 2020
f331f15
dwi2mask trace: Code cleanup
Lestropie Jun 18, 2020
9fc7c85
Merge pull request #9 from Lestropie/dwi2mask_warda_updates_day3
Lestropie Jun 18, 2020
19033e2
Docs: Include documentation for dwi2mask 3dautomask and dwi2mask trace
Lestropie Jun 18, 2020
4f4b55c
dwi2mask: Add config file options
Lestropie Jun 18, 2020
840adaf
dwi2mask: Multiple changes
Lestropie Jun 18, 2020
ce4511a
Merge pull request #10 from Lestropie/dwi2mask_config
Lestropie Jun 18, 2020
2d0de17
dwi2mask consensus: Fix final consensus operation
Lestropie Jun 19, 2020
925506f
dwi2mask consensus: Write algorithm errors to text files
Lestropie Jun 19, 2020
c9e3d75
dwi2mask: Update copyright
Lestropie Jun 19, 2020
a7028b0
dwi2mask consensus: Keep algorithm scratch directories
Lestropie Jun 22, 2020
1b52d40
dwi2mask: Add missing import functions
Lestropie Jun 22, 2020
65097a0
maskfilter: New filter "bigblob"
Lestropie Jun 24, 2020
70ec34d
Merge pull request #11 from Lestropie/maskfilter_bigblob
Lestropie Jun 24, 2020
98b00b9
Add file missing from 65097a04
Lestropie Jun 24, 2020
cf1360f
dwi2mask trace: Experiment with iterative shell weighting
Lestropie Sep 3, 2020
92a9cad
dwi2mask trace changes
Lestropie Oct 10, 2020
74eb0c4
dwi2mask trace: Option group for iterative algorithm version
Lestropie Oct 10, 2020
8a724f8
dwi2mask trace: Fix setting mutually exclusive options
Lestropie Oct 10, 2020
8ea98b1
dwi2mask template: Trying using Quick SyN for ANTs
Lestropie Oct 11, 2020
cafc8bf
dwi2mask template: Provide two different ANTs registration methods
Lestropie Oct 11, 2020
db1a246
Update documentation for Python dwi2mask
Lestropie Oct 11, 2020
8309e2a
dwibiascorrect: Fix dwi2mask invocation for Python port
Lestropie Oct 11, 2020
311fd14
Docs: FBA ST: Fix dwi2mask call for Python port
Lestropie Oct 11, 2020
bf3e504
dwi2mask template: Fix "antsfull" registration call
Lestropie Oct 12, 2020
8d4794d
dwi2mask trace: Move -volumes option to "dwi2mask mean"
Lestropie Oct 12, 2020
e2575f1
dwi2mask: Exclude empty voxels from mask
Lestropie Oct 12, 2020
df74e25
Docs: New page on DWI masking
Lestropie Oct 12, 2020
bb765ab
.gitignore: Ignore compiled docs
Lestropie Oct 12, 2020
7bce506
dwi2mask template: Use "antsquick" by default
Lestropie Oct 12, 2020
874c6ce
CI: Remove outdated dwi2mask binary test
Lestropie Oct 12, 2020
97369a5
Fix copyright in new file core/filter/bigblob.h
Lestropie Oct 12, 2020
8d4f251
Docs: Update dwi2mask template for 7bce5063
Lestropie Oct 12, 2020
5d5c5da
dwi2mask trace: Remove references to -volumes option
Lestropie Oct 13, 2020
7069580
Docs: DWI masking: ants algorithm also requires template
Lestropie Oct 13, 2020
5e2022a
dwi2mask: Fix various bugs in Python port
Lestropie Oct 13, 2020
69bd58f
Add tests for Python dwi2mask
Lestropie Oct 13, 2020
0ff4f58
dwi2mask: Further fixes to Python port from testing
Lestropie Oct 13, 2020
ac632e2
Merge branch 'dev' into dwi2mask
Lestropie Oct 13, 2020
f73725f
Docs: Hyperlinks to DWI brain masking page in pipelines
Lestropie Oct 14, 2020
1b1dd3a
dwi2mask consensus: Add -threshold option
Lestropie Oct 14, 2020
8e017f1
dwi2mask template: Multiple changes
Lestropie Oct 15, 2020
d01a6a3
dwi2mask: Multiple fixes
Lestropie Oct 15, 2020
b641cac
dwi2mask template: Various fixes
Lestropie Oct 15, 2020
cfa6e1a
dwi2mask template: More fixes from testing
Lestropie Oct 15, 2020
3609e7a
dwi2mask template: Final fix for loading ANTs registration parameters…
Lestropie Oct 15, 2020
7392f66
dwi2mask template: Issue message on fmirt config absence
Lestropie Oct 21, 2020
cc02b18
dwi2mask template: Rename algorithm to "b02template"
Lestropie Oct 21, 2020
14fbf37
Merge pull request #2 from Lestropie/dwi2mask_template
Lestropie Oct 21, 2020
37fde14
dwi2mask b02template: Fix stripping of line continuation characters
Lestropie Oct 27, 2020
3321c0f
maskfilter: Remove "bigblob", add "fill"
Lestropie Nov 18, 2020
eb185ea
Script tests: Update for dwi2mask "template" -> "b02template"
Lestropie Nov 18, 2020
eaf98cb
dwi2mask trace: Import Regenerated data
Lestropie Nov 18, 2020
cfecb67
Docs: Fix ref to dwi2mask b02template -algorithm antsfull
Lestropie Jan 22, 2021
219d6ed
Merge remote-tracking branch 'MRtrix3/dev' into dwi2mask
Lestropie Feb 8, 2021
4588246
dwifslpreproc: Do not attempt to pipe with dwi2mask
Lestropie Feb 8, 2021
4fd8f5d
Update copyright for new files in #2197
MRtrixBot Feb 8, 2021
21e718b
dwi2mask: Update shebang to match #2215
Lestropie Feb 8, 2021
e9863a0
dwi2mask consensus: Update for renamed dwi2mask algo
Lestropie Feb 8, 2021
173c814
dwi2mask: Pylint fix
Lestropie Feb 8, 2021
9245d0c
Update help page copyright for new files in #2197
MRtrixBot Feb 8, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ build.*
/dev/
/bin/
/tmp/
/compiled_docs/
/.vscode/
.cproject
.idea
Expand Down
103 changes: 103 additions & 0 deletions bin/dwi2mask
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/python3

# Copyright (c) 2008-2021 the MRtrix3 contributors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Covered Software is provided under this License on an "as is"
# basis, without warranty of any kind, either expressed, implied, or
# statutory, including, without limitation, warranties that the
# Covered Software is free of defects, merchantable, fit for a
# particular purpose or non-infringing.
# See the Mozilla Public License v. 2.0 for more details.
#
# For more details, see http://www.mrtrix.org/.



def usage(cmdline): #pylint: disable=unused-variable
from mrtrix3 import algorithm, app #pylint: disable=no-name-in-module, import-outside-toplevel

cmdline.set_author('Robert E. Smith (robert.smith@florey.edu.au) and Warda Syeda (wtsyeda@unimelb.edu.au)')
cmdline.set_synopsis('Generate a binary mask from DWI data')
cmdline.add_description('This script serves as an interface for many different algorithms that generate a binary mask from DWI data in different ways. '
'Each algorithm available has its own help page, including necessary references; e.g. to see the help page of the \'fslbet\' algorithm, type \'dwi2mask fslbet\'.')

# General options
#common_options = cmdline.add_argument_group('General dwi2mask options')
app.add_dwgrad_import_options(cmdline)

# Import the command-line settings for all algorithms found in the relevant directory
algorithm.usage(cmdline)



def execute(): #pylint: disable=unused-variable
from mrtrix3 import MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import algorithm, app, image, path, run #pylint: disable=no-name-in-module, import-outside-toplevel

# Find out which algorithm the user has requested
alg = algorithm.get_module(app.ARGS.algorithm)

app.check_output_path(app.ARGS.output)

input_header = image.Header(path.from_user(app.ARGS.input, False))
image.check_3d_nonunity(input_header)
grad_import_option = app.read_dwgrad_import_options()
if not grad_import_option and 'dw_scheme' not in input_header.keyval():
raise MRtrixError('Script requires diffusion gradient table: '
'either in image header, or using -grad / -fslgrad option')

app.make_scratch_dir()

# Get input data into the scratch directory
run.command('mrconvert ' + path.from_user(app.ARGS.input) + ' ' + path.to_scratch('input.mif')
+ ' -strides 0,0,0,1' + grad_import_option)
alg.get_inputs()

app.goto_scratch_dir()

# Generate a mean b=0 image (common task in many algorithms)
if alg.needs_mean_bzero():
run.command('dwiextract input.mif -bzero - | '
'mrmath - mean - -axis 3 | '
'mrconvert - bzero.nii -strides +1,+2,+3')

# Get a mask of voxels for which the DWI data are valid
# (want to ensure that no algorithm includes any voxels where
# there is no valid DWI data, regardless of how they operate)
run.command('mrmath input.mif max - -axis 3 | '
'mrthreshold - -abs 0 -comparison gt input_pos_mask.mif')

# Make relative strides of three spatial axes of output mask equivalent
# to input DWI; this may involve decrementing magnitude of stride
# if the input DWI is volume-contiguous
strides = image.Header('input.mif').strides()[0:3]
strides = [(abs(value) + 1 - min(abs(v) for v in strides)) * (-1 if value < 0 else 1) for value in strides]

# From here, the script splits depending on what algorithm is being used
# The return value of the execute() function should be the name of the
# image in the scratch directory that is to be exported
mask_path = alg.execute()

# Before exporting the mask image, get a mask of voxels for which
# the DWI data are valid
# (want to ensure that no algorithm includes any voxels where
# there is no valid DWI data, regardless of how they operate)
run.command('mrcalc '
+ mask_path
+ ' input_pos_mask.mif -mult -'
+ ' |'
+ ' mrconvert - '
+ path.from_user(app.ARGS.output)
+ ' -strides ' + ','.join(str(value) for value in strides),
mrconvert_keyval=path.from_user(app.ARGS.input, False),
force=app.FORCE_OVERWRITE)



# Execute the script
import mrtrix3 #pylint: disable=wrong-import-position
mrtrix3.execute() #pylint: disable=no-member
4 changes: 2 additions & 2 deletions bin/dwi2response
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def usage(cmdline): #pylint: disable=unused-variable


def execute(): #pylint: disable=unused-variable
from mrtrix3 import MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import CONFIG, MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import algorithm, app, image, path, run #pylint: disable=no-name-in-module, import-outside-toplevel

# Find out which algorithm the user has requested
Expand Down Expand Up @@ -106,7 +106,7 @@ def execute(): #pylint: disable=unused-variable
raise MRtrixError('Provided mask image needs to be a 3D image')
else:
app.console('Computing brain mask (dwi2mask)...')
run.command('dwi2mask dwi.mif mask.mif', show=False)
run.command('dwi2mask ' + CONFIG.get('Dwi2maskAlgorithm', 'legacy') + ' dwi.mif mask.mif', show=False)

if not image.statistics('mask.mif', mask='mask.mif').count:
raise MRtrixError(('Provided' if app.ARGS.mask else 'Generated') + ' mask image does not contain any voxels')
Expand Down
4 changes: 2 additions & 2 deletions bin/dwibiascorrect
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def usage(cmdline): #pylint: disable=unused-variable


def execute(): #pylint: disable=unused-variable
from mrtrix3 import MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import CONFIG, MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import algorithm, app, image, path, run #pylint: disable=no-name-in-module, import-outside-toplevel

# Find out which algorithm the user has requested
Expand Down Expand Up @@ -67,7 +67,7 @@ def execute(): #pylint: disable=unused-variable
if not image.match('in.mif', 'mask.mif', up_to_dim=3):
raise MRtrixError('Provided mask image does not match input DWI')
else:
run.command('dwi2mask in.mif mask.mif')
run.command('dwi2mask ' + CONFIG.get('Dwi2maskAlgorithm', 'legacy') + ' in.mif mask.mif')

# From here, the script splits depending on what estimation algorithm is being used
alg.execute()
Expand Down
19 changes: 15 additions & 4 deletions bin/dwifslpreproc
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def execute(): #pylint: disable=unused-variable

# Need gradient table if running dwi2mask after applytopup to derive a brain mask for eddy
run.command('mrinfo dwi.mif -export_grad_mrtrix grad.b')

dwi2mask_algo = CONFIG.get('Dwi2maskAlgorithm', 'legacy')

eddy_in_topup_option = ''
dwi_post_eddy_crop_option = ''
Expand Down Expand Up @@ -911,10 +911,18 @@ def execute(): #pylint: disable=unused-variable

# Use the initial corrected volumes to derive a brain mask for eddy
if not app.ARGS.eddy_mask:

dwi2mask_out_path = 'dwi2mask_out.mif'
if len(applytopup_image_list) == 1:
run.command('dwi2mask ' + applytopup_image_list[0] + ' - | maskfilter - dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3')
dwi2mask_in_path = applytopup_image_list[0]
else:
run.command('mrcat ' + ' '.join(applytopup_image_list) + ' - -axis 3 | dwi2mask - - | maskfilter - dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3')
dwi2mask_in_path = 'dwi2mask_in.mif'
run.command('mrcat ' + ' '.join(applytopup_image_list) + ' ' + dwi2mask_in_path + ' -axis 3')
run.command('dwi2mask ' + dwi2mask_algo + ' ' + dwi2mask_in_path + ' ' + dwi2mask_out_path)
run.command('maskfilter ' + dwi2mask_out_path + ' dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3')
if len(applytopup_image_list) > 1:
app.cleanup(dwi2mask_in_path)
app.cleanup(dwi2mask_out_path)

app.cleanup(applytopup_image_list)

Expand All @@ -924,7 +932,10 @@ def execute(): #pylint: disable=unused-variable

# Generate a processing mask for eddy based on the uncorrected input DWIs
if not app.ARGS.eddy_mask:
run.command('dwi2mask ' + dwi_path + ' - | maskfilter - dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3')
dwi2mask_out_path = 'dwi2mask_out.mif'
run.command('dwi2mask ' + dwi2mask_algo + ' ' + dwi_path + ' ' + dwi2mask_out_path)
run.command('maskfilter ' + dwi2mask_out_path + ' dilate - | mrconvert - eddy_mask.nii -datatype float32 -strides -1,+2,+3')
app.cleanup(dwi2mask_out_path)


# Use user supplied mask for eddy instead of one derived from the images using dwi2mask
Expand Down
4 changes: 2 additions & 2 deletions bin/dwigradcheck
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def usage(cmdline): #pylint: disable=unused-variable


def execute(): #pylint: disable=unused-variable
from mrtrix3 import MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import CONFIG, MRtrixError #pylint: disable=no-name-in-module, import-outside-toplevel
from mrtrix3 import app, image, matrix, path, run #pylint: disable=no-name-in-module, import-outside-toplevel

image_dimensions = image.Header(path.from_user(app.ARGS.input, False)).size()
Expand Down Expand Up @@ -87,7 +87,7 @@ def execute(): #pylint: disable=unused-variable
# Note that gradient table must be explicitly loaded, since there may not
# be one in the image header (user may be relying on -grad or -fslgrad input options)
if not os.path.exists('mask.mif'):
run.command('dwi2mask data.mif mask.mif -grad grad.b')
run.command('dwi2mask ' + CONFIG.get('Dwi2maskAlgorithm', 'legacy') + ' data.mif mask.mif -grad grad.b')

# How many tracks are we going to generate?
number_option = ' -select ' + str(app.ARGS.number)
Expand Down
115 changes: 0 additions & 115 deletions cmd/dwi2mask.cpp

This file was deleted.

Loading