Add per-channel norm support for render_images#572
Merged
Conversation
Accept a list of Normalize objects in render_images so each channel can be normalized independently — essential for multi-channel protein data with vastly different intensity ranges. The rendering pipeline already reads per-channel norms from CmapParams, so this change only widens the input validation and routes per-channel norms into the existing CmapParams creation loop. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…s only - Use resolved per-element cmap for list branching so norm list works correctly when cmap is auto-replicated - Raise ValueError when norm is a list but cmap is not (no silent pass-through to _prepare_cmap_norm) - Restrict list norm validation to element_type="images" only — labels has no list-norm support - Add test for norm list without explicit cmap list Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Using the resolved (replicated) cmap for branching broke the scalar cmap path — e.g. grayscale=True with cmap="viridis" entered the list branch because the cmap was internally replicated to match channels. Now only use the resolved cmap when norm is a list (the new feature path); otherwise preserve the original user-supplied cmap for branching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #572 +/- ##
==========================================
- Coverage 75.61% 75.17% -0.44%
==========================================
Files 10 10
Lines 2908 2929 +21
Branches 672 681 +9
==========================================
+ Hits 2199 2202 +3
- Misses 428 445 +17
- Partials 281 282 +1
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Improve error message when norm list + cmap resolution fails — now mentions cmap/channel mismatch as possible cause instead of the misleading "multiple colormaps are used" 2. Unwrap length-1 cmap_params lists to scalar so single-channel images still take the fast path (proper norm in imshow + colorbar) 3. Make Normalize copy unconditional in the multi-channel compositing loop — eliminates fragile conditional that only copied auto-ranging norms, preventing any future cross-channel mutation bugs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…selected When user specifies `channel=[0]` on a 3-channel image with `cmap=['gray']`, the cmap matched the selected channel count but was nullified because it didn't match the full image channel count. Now the comparison uses the selected channel count (or full count when no channel is specified). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Simplify error: "When 'norm' is a list, you must also pass a list of colormaps via 'cmap' with matching length" - Add test locking the cmap validation fix: cmap=['gray'] with channel=[0] on a 3-channel image should succeed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restructure branching so scalar cmap_params is built directly when there's only one cmap (len <= 1), instead of building a list and unwrapping after. Also handles norm=[single_Normalize] gracefully by extracting the scalar. Shortens the effective_cmap comment to one line. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When norm is a list but no cmap is provided, auto-generate a default cmap list (one per norm) so the per-channel rendering path works. Users shouldn't need to write cmap=[plt.cm.gray]*3 just to use per-channel normalization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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_imagesnow accepts a list ofNormalizeobjects for per-channel normalizationCmapParams— this change only widens validation and routes per-channel norms into the existingCmapParamscreation loopChanges
basic.py: Widennormtype tolist[Normalize] | Normalize | None, update docstring, zip norm list with cmap listutils.py: Acceptlist[Normalize]in validation, reject empty lists and non-Normalize elementstest_render_images.py: 5 new tests (per-channel norm, backward compat, length mismatch, empty list, invalid element)Usage