Skip to content

feat(n4): GPU-accelerated N4 bias field correction#109

Closed
FIrgolitsch wants to merge 518 commits into
chain-mergedfrom
pr-n4-bias-field
Closed

feat(n4): GPU-accelerated N4 bias field correction#109
FIrgolitsch wants to merge 518 commits into
chain-mergedfrom
pr-n4-bias-field

Conversation

@FIrgolitsch

@FIrgolitsch FIrgolitsch commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Stacked PR 11/16 — review order: #95#97#98#99#100#101#108#106#107#87#109#110#111#40#112#113

Base: pr-3-slice-interpolation (#87). Retargets to main as upstream PRs merge.


PR #109 — N4 Bias Field Correction (CPU + GPU)

Adds N4 bias-field correction with CPU/GPU backends, replacing the previous z-intensity normalization.

Library

  • linumpy/intensity/bias_field.py — high-level API
  • linumpy/intensity/normalization.py — extended for N4 backend, plus fix(normalize): zero agarose per slice while preserving inter-slice brightness (per-slice subtraction of the agarose-median floor pins background voxels to exactly 0 in the normalized output, restoring pre-n4 visualization behavior; global divisor preserves the 2:1 inter-section brightness invariant)
  • linumpy/gpu/{bias_field,bspline,n4}.py — GPU kernels (CuPy)
  • Removes linumpy/gpu/normalization.py (superseded)

Scripts

  • scripts/linum_correct_bias_field.py — replaces linum_normalize_z_intensity
  • scripts/diagnostics/linum_benchmark_n4_gpu.py
  • scripts/diagnostics/linum_n4_gpu_visual_compare.py

Tests

  • linumpy/tests/test_bias_field*.py, test_gpu_{bspline,n4}.py
  • linumpy/tests/test_n4_gpu_{equivalency,perf}.py
  • Extended test_intensity_normalization.py with test_normalize_volume_agarose_floor_at_zero

Workflow integration

  • workflows/reconst_3d/soct_3d_reconst.nf: adds correct_bias_field process
  • workflows/reconst_3d/nextflow.config: N4 parameters

Build

  • pyproject.toml: entry-point swap (linum_normalize_z_intensitylinum_correct_bias_field), scipy-stubs/networkx-stubs dev deps, lint exemptions for linumpy/gpu/* and N4 diagnostic scripts

joe-from-mtl and others added 30 commits April 9, 2025 15:58
The new function detects the galvo shift using the normalized mutual information between the galvo return and the image.
Scripts to perform and apply manual correction to 2.5D volume
…and refactor volume loading to support JSON configuration
2.5D/3D reconstruction pipelines bug fixes
Copilot recommendation

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Charles Poirier <41654474+CHrlS98@users.noreply.github.com>
Co-authored-by: Charles Poirier <41654474+CHrlS98@users.noreply.github.com>
@FIrgolitsch

Copy link
Copy Markdown
Contributor Author

Superseded by #116 — recreated on the proper base pr-3-slice-interpolation since GitHub permanently locked this PR closed (its base chain-merged had no common history).

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.

5 participants