Skip to content

Fix widget compatibility with multi-scale napari image layers#267

Merged
JoOkuma merged 4 commits intomainfrom
fix/widget-multiscale-image-layers
Apr 10, 2026
Merged

Fix widget compatibility with multi-scale napari image layers#267
JoOkuma merged 4 commits intomainfrom
fix/widget-multiscale-image-layers

Conversation

@JoOkuma
Copy link
Copy Markdown
Member

@JoOkuma JoOkuma commented Apr 10, 2026

Problem

When a napari Image layer is multi-scale (e.g. loaded from a zarr pyramid or created with viewer.add_image(..., multiscale=True)), its .data attribute is a MultiScaleData object — a list of arrays at progressively lower resolutions — rather than a single array.

The widget's workflow code passed layer.data directly to processing functions and called .shape on it, which raised:

TypeError: list indices must be integers or slices, not tuple

This affected all three workflow modes (AUTO_DETECT, AUTO_FROM_LABELS, MANUAL).

Fix

Added get_layer_data(layer) helper in utils.py that returns layer.data[0] (the highest-resolution level) when a layer is multi-scale, and layer.data otherwise.

Applied it in workflows.py at every point where user-supplied layer data is consumed:

  • preprocessing step (image → auto-detect, labels → auto-from-labels)
  • segmentation step (detection and contours in manual mode)
  • optical flow computation

Tests

Added test_ultrack_widget_multiscale parametrized over all three workflow choices, each using a two-level image pyramid built from the existing mock data fixtures. The tests confirmed the failure before the fix and pass after.

JoOkuma added 4 commits April 10, 2026 11:15
Napari multi-scale Image layers store data as a MultiScaleData list
rather than a single array. Passing this directly to processing
functions caused a TypeError when the code tried to index or call
.shape on it.

Add get_layer_data() helper in utils.py that extracts the
highest-resolution level (index 0) for multi-scale layers and
returns .data unchanged for regular layers. Apply it in workflows.py
at every point where user-supplied layer data is consumed:
preprocessing (image/labels), segmentation (detection/contours), and
optical flow.

Add regression tests covering all three workflow modes (AUTO_DETECT,
AUTO_FROM_LABELS, MANUAL) with two-level image pyramids.
The CLI already had the same multiscale-extraction pattern inline in
flow.py, link.py, export.py, and as a private function in segment.py.
Consolidate all five copies into a single get_layer_data() in
ultrack/utils/napari.py and update every call site to import from
there.
@JoOkuma JoOkuma force-pushed the fix/widget-multiscale-image-layers branch from 1b999cf to d669a3a Compare April 10, 2026 19:14
@JoOkuma JoOkuma merged commit 56fa232 into main Apr 10, 2026
3 checks passed
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.

1 participant