Skip to content

Complete N4 bias field rescaling pipeline - #188

Merged
akhanf merged 2 commits into
n4-rescalingfrom
copilot/complete-todos-n4-rescaling
Jul 23, 2026
Merged

Complete N4 bias field rescaling pipeline#188
akhanf merged 2 commits into
n4-rescalingfrom
copilot/complete-todos-n4-rescaling

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The N4 bias field correction pipeline had several incomplete TODOs: the calc_n4_rescaling rule in segmentation.smk had syntax errors and pointed to a non-existent script, and n4_biasfield.py had placeholder #TODO comments for reading scale/offset values.

Changes

  • pyproject.toml: Switch zarrnii to branch copilot/add-scale-and-offset-options, which adds scale and offset parameters to N4BiasFieldApply

  • segmentation.smk: Fix calc_n4_rescaling rule — extra leading space before input:, missing ) closing the mask=bids(...) call, added resources block, removed #TODO comment

  • scripts/calc_n4_rescaling.py (new): Computes the linear scale/offset to map the bias-corrected intensity range back to the original input min/max within the brain mask, and writes them to a scaleoffset.txt file:

    # corrected * scale + offset => [input_min, input_max]
    scale = (input_max - input_min) / (corrected_max - corrected_min)
    offset = input_min - scale * corrected_min
    
  • scripts/n4_biasfield.py: Reads scale/offset from the txt file (with key-presence validation) and passes them to N4BiasFieldApply:

    N4BiasFieldApply(log_space=True, scale=scale, offset=offset)

Copilot AI added 2 commits July 23, 2026 03:10
@akhanf
akhanf marked this pull request as ready for review July 23, 2026 03:15
@akhanf
akhanf merged commit ebd0104 into n4-rescaling Jul 23, 2026
1 check failed
@akhanf
akhanf deleted the copilot/complete-todos-n4-rescaling branch July 23, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants