Skip to content

Commit

Permalink
SynthSR+SyN for fieldmap-less distortion correction (#50)
Browse files Browse the repository at this point in the history
This implements a novel SynthSR+SyN method for fieldmap-less distortion correction. It is similar to the SyN method used in SDCFlows, except, the b0 and T1w images are transformed to T1w-like 1mm images before performing registration, which makes the registration much more robust.

This is now set-up as a the default method to use when topup cannot be used (ie no opposite phase encoding directions).

Also a couple other miscellaneous changes here:

-add shadow to synthstrip/synthsr rules
-disable bedpost by default
  • Loading branch information
akhanf authored Feb 20, 2023
1 parent e4fa486 commit e8cd566
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 14 deletions.
38 changes: 28 additions & 10 deletions snakedwi/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ derivatives: False
analysis_levels: &analysis_levels
- participant

no_topup: False
use_eddy_s2v: False
eddy_no_quad: False
no_bedpost: False
use_syn_sdc: False

targets_by_analysis_level:
participant:
Expand Down Expand Up @@ -92,10 +87,16 @@ parse_args:
action: 'store_true'
default: False

--no_bedpost:
help: 'Disable bedpost (default: %(default)s)'
action: 'store_true'
default: False
--use_bedpost:
help: 'Enable bedpost (disabled by default)'
action: 'store_false'
dest: 'no_bedpost'
default: True

# --no_bedpost:
# help: 'Disable bedpost (default: %(default)s)'
# action: 'store_true'
# default: True


--use_eddy_s2v:
Expand Down Expand Up @@ -156,6 +157,16 @@ parse_args:
action: 'store_true'
default: False

# --synthsr_sdc:
#help: "Enable SynthSR+SyN fieldmap-less distortion-correction. This uses SynthSR to transform T1w and b0 images to the same 1mm T1w contrast prior to non-linear registration to obtain a field-map. (default: %(default)s)"
#action: 'store_true'
#default: True

--no_synthsr_sdc:
help: "Disable SynthSR+SyN fieldmap-less distortion-correction (enabled by default)"
action: 'store_false'
dest: 'use_synthsr_sdc'
default: True


#---- to update below this
Expand All @@ -173,6 +184,9 @@ singularity:
python: 'docker://khanlab/pythondeps-snakedwi:v0.2.0'
synthstrip: 'docker://freesurfer/synthstrip:1.3'
sdcflows: 'docker://nipreps/fmriprep:22.1.1' #can't currently just use sdcflows docker as it is missing freesurfer's mri_robust_template
synthsr: 'docker://akhanf/synthsr:main'
synthmorph: 'docker://freesurfer/synthmorph:1'




Expand Down Expand Up @@ -281,6 +295,7 @@ eddy:
default_effective_echo_spacing: 0.0001 #if not defined in JSON files

#for test data
root: 'results'
participant_label:
exclude_participant_label:
masking_method: b0_synthstrip
Expand All @@ -292,4 +307,7 @@ use_eddy_gpu: False
use_bedpost_gpu: False
rigid_dwi_t1_init: 'identity'
rigid_dwi_t1_iters: '50x50'
root: 'results'
eddy_no_quad: False
no_topup: False
use_syn_sdc: False
use_synthsr_sdc: True
22 changes: 22 additions & 0 deletions snakedwi/workflow/rules/eddy.smk
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def get_eddy_topup_fmap_input(wildcards):
**subj_wildcards,
).format(**wildcards),
}
elif method == "synthsr":
return {
"fmap": bids(
root=work,
datatype="dwi",
suffix="fmap.nii.gz",
desc="b0",
method="synthSRsdc",
**subj_wildcards,
).format(**wildcards)
}
elif method == "syn":
return {
"fmap": bids(
Expand Down Expand Up @@ -130,6 +141,17 @@ def get_eddy_topup_fmap_opt(wildcards, input):
root=work, suffix="topup", datatype="dwi", **subj_wildcards
).format(**wildcards)
return f"--topup={topup_prefix}"
elif method == "synthsr":
fmap_prefix = bids(
root=work,
datatype="dwi",
suffix="fmap",
desc="b0",
method="synthSRsdc",
**subj_wildcards,
).format(**wildcards)
return f"--field={fmap_prefix}"

elif method == "syn":
fmap_prefix = bids(
root=work,
Expand Down
2 changes: 2 additions & 0 deletions snakedwi/workflow/rules/masking_b0_synthstrip.smk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ rule synthstrip_b0:
container:
config["singularity"]["synthstrip"]
threads: 8
shadow:
"minimal"
group:
"subj"
shell:
Expand Down
2 changes: 2 additions & 0 deletions snakedwi/workflow/rules/reg_dwi_to_t1.smk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ rule synthstrip_t1:
container:
config["singularity"]["synthstrip"]
threads: 8
shadow:
"minimal"
shell:
"python3 /freesurfer/mri_synthstrip -i {input.t1} -m {output.mask}"

Expand Down
8 changes: 4 additions & 4 deletions snakedwi/workflow/rules/reg_t1_to_template.smk
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ rule convert_template_xfm_ras2itk:
datatype="transforms",
**subj_wildcards,
suffix="xfm.txt",
from_="subject",
to="{template}",
from_="{from}",
to="{to}",
desc="{desc}",
type_="ras"
),
Expand All @@ -65,8 +65,8 @@ rule convert_template_xfm_ras2itk:
datatype="transforms",
**subj_wildcards,
suffix="xfm.txt",
from_="subject",
to="{template}",
from_="{from}",
to="{to}",
desc="{desc}",
type_="itk"
),
Expand Down
Loading

0 comments on commit e8cd566

Please sign in to comment.