Implement modified N4 masking for high-res applications - #190
Conversation
zarrnii v0.21.2 now will just set voxels outside mask to zero when using mask with n4 apply biasfield.. however high-res apply with mask uses more memory, so using experimental version here to break down the n4 into two steps (rechunk to local, then apply n4)
There was a problem hiding this comment.
🟡 Not ready to approve
The new unconditional temp OME-Zarr round-trip can significantly increase I/O and local scratch usage and may cause failures on environments with limited/slow temp storage unless made configurable/conditional.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR updates SPIMquant’s N4 bias field correction workflow to better support mask-aware correction and align with newer zarrnii behavior, improving accuracy/compatibility for high-resolution use cases.
Changes:
- Add a brain mask input to the
n4_biasfieldSnakemake rule and pass it through to the bias field application script. - Update
n4_biasfield.pyto materialize inputs to a temporary OME-Zarr and apply the low-res bias field using a low-res mask. - Bump
zarrniidependency from0.21.1to0.21.2(and update lockfile) to pick up required features.
File summaries
| File | Description |
|---|---|
| spimquant/workflow/scripts/n4_biasfield.py | Adds temp OME-Zarr materialization and passes a low-res mask into scaled bias-field application. |
| spimquant/workflow/rules/segmentation.smk | Extends the n4_biasfield rule to include a BIDS-resolved mask input. |
| pyproject.toml | Updates the zarrnii version constraint to >=0.21.2,<0.22.0. |
| pixi.lock | Locks zarrnii to 0.21.2 and updates associated hashes/entries. |
Review details
Comments suppressed due to low confidence (1)
spimquant/workflow/scripts/n4_biasfield.py:30
- The comment says "try first saving to /tmp", but the code always uses the temp OME-Zarr round-trip and it may not be /tmp depending on TMPDIR settings. Suggest updating the comment to reflect what the code actually does.
# try first saving to /tmp
- Files reviewed: 3/4 changed files
- Comments generated: 1
- Review effort level: Low
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
only when imaris is used
There was a problem hiding this comment.
🟢 Ready to approve
The changes are consistent with the workflow’s existing mask dependency and correctly wire mask-aware bias correction while keeping the temp materialization limited to the .ims backend.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 3/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
This pull request updates the bias field correction workflow to improve compatibility and accuracy, especially when working with masks and the latest
zarrniilibrary. The most important changes are grouped below:Dependency Updates:
zarrniidependency to version>=0.21.2,<0.22.0inpyproject.tomlto ensure compatibility with new features, such as mask support in bias field correction.Workflow and Rule Enhancements:
n4_biasfieldrule insegmentation.smkto include amaskinput, which will be used for more precise bias field correction.Script Improvements (Bias Field Correction):
tempfilemodule inn4_biasfield.pyto support temporary directory usage for intermediate file storage.ZarrNiiobjects from NIfTI files.lowres_mask) to the scaled processing step, enabling mask-aware bias field correction.