Skip to content

ENH: Allow changing laplacians weights in SyN registration metric #484

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

Merged
merged 2 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion sdcflows/data/sd_syn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dimension": 3,
"interpolation": "Linear",
"metric": [ ["Mattes", "Mattes"], ["Mattes", "Mattes"] ],
"metric_weight": [ [0.5, 0.5], [0.5, 0.5] ],
"metric_weight": [ [0.9, 0.1], [0.8, 0.2] ],
"number_of_iterations": [ [ 200, 100 ], [ 10 ] ],
"output_transform_prefix": "fmap_syn",
"radius_or_number_of_bins": [ [48, 48], [48, 48] ],
Expand Down
2 changes: 1 addition & 1 deletion sdcflows/data/sd_syn_sloppy.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dimension": 3,
"interpolation": "Linear",
"metric": [ ["Mattes", "Mattes"], ["Mattes", "Mattes"] ],
"metric_weight": [ [0.5, 0.5], [0.5, 0.5] ],
"metric_weight": [ [0.9, 0.1], [0.8, 0.2] ],
"number_of_iterations": [ [ 20, 10 ], [ 2 ] ],
"output_transform_prefix": "fmap_syn",
"radius_or_number_of_bins": [ [48, 48], [48, 48] ],
Expand Down
17 changes: 17 additions & 0 deletions sdcflows/workflows/fit/syn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"anat_mask",
"sd_prior",
)
MAX_LAPLACIAN_WEIGHT = 0.5


def init_syn_sdc_wf(
Expand All @@ -48,6 +49,7 @@
debug=False,
name="syn_sdc_wf",
omp_nthreads=1,
laplacian_weight=None,
sd_prior=True,
**kwargs,
):
Expand Down Expand Up @@ -82,6 +84,11 @@
Name for this workflow
omp_nthreads : :obj:`int`
Parallelize internal tasks across the number of CPUs given by this option.
laplacian_weight : :obj:`tuple` (optional)
Tuple of two weights of the Laplacian term in the SyN cost function (one weight per
registration level).
sd_prior : :obj:`bool`
Enable using a prior map to regularize the SyN cost function.

Inputs
------
Expand Down Expand Up @@ -229,6 +236,16 @@
syn.inputs.output_warped_image = debug
syn.inputs.output_inverse_warped_image = debug

if laplacian_weight is not None:
laplacian_weight = (

Check warning on line 240 in sdcflows/workflows/fit/syn.py

View check run for this annotation

Codecov / codecov/patch

sdcflows/workflows/fit/syn.py#L240

Added line #L240 was not covered by tests
max(min(laplacian_weight[0], MAX_LAPLACIAN_WEIGHT), 0.0),
max(min(laplacian_weight[1], MAX_LAPLACIAN_WEIGHT), 0.0),
)
syn.inputs.metric_weight = [

Check warning on line 244 in sdcflows/workflows/fit/syn.py

View check run for this annotation

Codecov / codecov/patch

sdcflows/workflows/fit/syn.py#L244

Added line #L244 was not covered by tests
[1.0 - laplacian_weight[0], laplacian_weight[0]],
[1.0 - laplacian_weight[1], laplacian_weight[1]],
]

if debug:
syn.inputs.args = "--write-interval-volumes 2"

Expand Down
Loading