Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the dtype-preservation and label-storage changes.
No open issues 🎉
What changed in this PR
This PR preserves image dtypes when saving layers and reduces label storage size without losing label values.
Changes:
- Preserve array dtypes in
save_layer, with optional narrowing of non-negative integer labels to the smallest unsigned dtype. - Update conversion utilities to use label-aware saving and preserve input dtype after anisotropy resizing.
- Make semantic conversion non-mutating and add regression tests for dtype preservation, label narrowing, and input immutability.
| File | Description |
|---|---|
napari_cellseg3d/utils.py |
Preserve saved dtypes and add optional label dtype optimization. |
napari_cellseg3d/code_plugins/plugin_convert.py |
Apply label-aware saving and remove forced dtype conversions. |
napari_cellseg3d/code_models/instance_segmentation.py |
Produce semantic masks without modifying the input. |
napari_cellseg3d/_tests/test_utils.py |
Test dtype-preserving saves and label narrowing. |
napari_cellseg3d/_tests/test_instance_segmentation.py |
Verify semantic conversion output and input immutability. |
Review effort: Balanced
C-Achard
marked this pull request as ready for review
November 20, 2026 09:12
C-Achard
force-pushed
the
cy/preserve-dtype
branch
from
November 20, 2026 09:36
6a1b3b4 to
3df6b28
Compare
C-Achard
force-pushed
the
cy/preserve-dtype
branch
from
November 20, 2026 17:09
3df6b28 to
fc4fbd9
Compare
This branch has not been deployed
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.
Stops
save_layerfrom casting every saved layer tofloat32. Images now keep their dtype, and labels are saved in the smallest uint that keeps the max label.Changes
utils.save_layerfloat32and written asfloat32.labels=Trueargument, non-negative integer labels are first narrowed with the newoptimize_labels_dtype(vianp.min_scalar_type). Floats, negative values and empty arrays unchanged.Utilities plugins (
plugin_convert.py)labels=True. Fragment and anisotropy passlabels=Trueonly when the input layer is aLabelslayer.uint16.float32and shown as the image dtype oruint16.instance_segmentation.to_semanticNo longer modifies:
imageimage >= 1] = 1replaced by(image >= 1).astype(np.uint16).Stack created with GitHub Stacks CLI • Give Feedback 💬