Fix multi-channel compositing and add per-channel norm support#451
Draft
Fix multi-channel compositing and add per-channel norm support#451
Conversation
Member
Author
|
@Sonja-Stockhaus did we discuss this at one point? I've been ignoring that warning for a long time because it's thrown my matplotlib and doesn't fail |
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
Nope. I also don't remember ever trying to render sth with 3+ channels |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #451 +/- ##
==========================================
+ Coverage 73.68% 74.50% +0.82%
==========================================
Files 9 9
Lines 2744 2750 +6
Branches 651 656 +5
==========================================
+ Hits 2022 2049 +27
+ Misses 447 419 -28
- Partials 275 282 +7
🚀 New features to boost your workflow:
|
Sonja-Stockhaus
pushed a commit
that referenced
this pull request
Jun 4, 2025
…nel norm Replace inconsistent compositing formulas in _render_images with a shared _additive_blend helper that implements standard additive blending with clamping, matching Napari/ImageJ/FIJI behavior. Fixes: - Averaging bug in paths 2A-cmap and 2D (divided by n_channels) - Missing clip in paths 2B (2-3ch) and 2C - Double-alpha bug in path 2B (4+ch) - Redundant isinstance(c, str) filter in path 2C Adds per-channel normalization support: render_images() now accepts norm as a list of Normalize objects (one per channel), enabling proper contrast control for multi-channel fluorescence data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2e991c5 to
92cb5eb
Compare
The `percentiles_for_norm` field on `ImageRenderParams` and its `quantiles_for_norm` deprecation alias were never wired into the rendering pipeline. Per-channel normalization is now handled via the `norm` parameter accepting a list of Normalize objects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updates 5 baseline images that changed due to the switch from averaging to additive blending in multi-channel image compositing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The naive additive blend (sum RGB + clip) only works with black-to-color LUTs. For white-to-color cmaps (e.g. Reds, Greens) it saturates to white; for diverging cmaps (e.g. seismic) it washes out. Signal-based blending subtracts each cmap's zero-value before summing, then composites onto a canvas colored by the mean zero-value. This reduces to standard additive for black-to-color LUTs (Napari/ImageJ) and to invert-add-invert for white-to-color LUTs (ImageJ Composite Invert), while producing reasonable results for arbitrary cmaps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 5-channel auto-color composite (path 2B, n>3): untested path - 5-channel fluorescence palette (DAPI + 4 markers): path 2C with n>3 - Per-channel norm list: new feature, independent contrast per channel - Single-element norm list: verifies list[Normalize] works for 1 channel Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Reuse pre-computed zero_colors array instead of calling cmap(0) twice - Add tests for norm list length mismatch and empty norm list - Remove unconditional multi-cmap warning (signal-based blend handles it) - Clarify norms field naming with inline comment Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace stringly-typed `_na.alpha == "00"` with the public accessor `_na.get_alpha_as_float() == 0.0` in all three groups-filtering guards. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ards - Reject tuple/sequence norms in _type_check_params with a clear TypeError pointing users to use a list instead - Extract na_is_transparent local in all three groups-filtering guards (shapes, points, labels) for consistent style - Add test_norm_tuple_raises Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updates 5 existing baselines affected by the signal-based blending change and adds 4 new baselines for per-channel normalization and 5-channel compositing tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
Could this PR help with #534? |
Member
Author
I think so 🤔 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_render_imageswith a shared_additive_blendhelper. For each channel, the "signal" (deviation fromcmap(0)) is summed onto a canvas colored by the mean zero-value. This handles both Napari-style additive blending (black-to-color LUTs) and ImageJ Composite Invert (white-to-color LUTs), and produces reasonable results for arbitrary colormaps.render_images(norm=...)now accepts a list ofNormalizeobjects for independent contrast control per channel (e.g. bright DAPI vs dim cytokine stain).percentiles_for_normfield and its deprecation alias.Bug fixes
_additive_blendnp.clipin_additive_blendimshowisinstance(c, str)filter in palette pathna_coloralpha compared via internal hex stringColor.get_alpha_as_float()public APIPer-channel norm usage
Test plan
Closes #416, #534. Addresses #370. Partially addresses #460 (per-channel norm, but not arbitrary preprocessing callables).
Note: #450 (PCA aggregation) is not addressed by this PR.