Skip to content

fix(itkwasm): fall back to the image size when the buffered region is empty - #1577

Merged
thewtex merged 2 commits into
InsightSoftwareConsortium:mainfrom
vboussot:fix/buffered-region-fallback
Aug 5, 2026
Merged

fix(itkwasm): fall back to the image size when the buffered region is empty#1577
thewtex merged 2 commits into
InsightSoftwareConsortium:mainfrom
vboussot:fix/buffered-region-fallback

Conversation

@vboussot

@vboussot vboussot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

shape = list(image.bufferedRegion.size or image.size)[::-1]

Context

#1545 switched the reshape source from size to bufferedRegion.size, which
information-only outputs need since they carry a logical size but no allocated
buffer.

Not every producer fills the buffered region though. Readers in
itkwasm-image-io 1.6.1 return it empty, so the reshape target became an
empty tuple and every read fails:

from itkwasm_image_io import imread
imread("cthead1.png")
# ValueError: cannot reshape array of size 65536 into shape ()
1.0b195 + image-io 1.6.1  ->  OK,   bufferedRegion=[]
1.0b199 + image-io 1.6.1  ->  ValueError

The change landed on 30 June but only surfaced when 1.0b199 shipped, since
nothing was published in between.

Two producers use two conventions, and one line has to serve both:

producer size bufferedRegion correct source
information-only output [10,34,34] [0,0,0] buffered region
file reader [256,256] [] size

or covers both without giving up either: [0,0,0] is a non-empty list and
still wins, [] falls back.

Validation

test_pipeline_image_without_buffered_region mirrors the information-only
test from #1545 for the empty case. It fails without this change and passes
with it, and the information-only test keeps passing either way.

Core Python suite: 35 passed, 4 skipped, excluding the Pyodide and JS package
config tests.

Downstream, ngff-zarr went from 23 CI failures to 811 passed against a patched
1.0b199, and reading a file then downsampling it through
itkwasm-downsample-cucim works end to end on a GPU.

Also worth a look

pyodide.py has a fallback but tests is not None, so it would miss this
case, which is a buffered region that is present with an empty size. Same
latent issue, same fix. I have not exercised that path.

… empty

InsightSoftwareConsortium#1545 switched the reshape source from size to bufferedRegion.size, which
information-only outputs need since they carry a logical size but no allocated
buffer.

Not every producer fills the buffered region though. Readers in
itkwasm-image-io 1.6.1 return it empty, so the reshape target became an empty
tuple and every read failed:

    from itkwasm_image_io import imread
    imread("cthead1.png")
    # ValueError: cannot reshape array of size 65536 into shape ()

The change landed on 30 June but only surfaced when 1.0b199 shipped, since
nothing was published in between.

Two producers use two conventions, and one line has to serve both:

    information-only  size=[10,34,34]  bufferedRegion=[0,0,0]  -> region
    file reader       size=[256,256]   bufferedRegion=[]       -> size

`or` covers both without giving up either: [0,0,0] is a non-empty list and
still wins, [] falls back.
@vboussot
vboussot requested a review from thewtex August 5, 2026 17:07
@vboussot
vboussot force-pushed the fix/buffered-region-fallback branch from 15359cb to ea12da1 Compare August 5, 2026 19:36
to_py() checked `is not None`, so a buffered region that is present but
carries an empty size still produced an empty reshape target. That is what
the emscripten readers return, and it fails the same way as the native
runtime:

    itkwasm_image_io_emscripten/read_image_async.py
    ValueError: cannot reshape array of size 10000 into shape ()

Fall back to the largest possible region when the buffered size is missing or
empty, matching pipeline.py.
@vboussot
vboussot force-pushed the fix/buffered-region-fallback branch from ea12da1 to 7f8054e Compare August 5, 2026 19:37
@vboussot

vboussot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@thewtex The remaining red check is main's red, not this PR's: itkwasm-python (ubuntu-24.04, 12, compare-images) runs the downstream packages' Pyodide tests against itkwasm 1.0b199 from PyPI. The same single job fails on main's latest Python Wasm run. It will turn green once this lands and itkwasm is republished; every job that exercises the branch's code passes.

@thewtex
thewtex merged commit 4912b84 into InsightSoftwareConsortium:main Aug 5, 2026
30 of 66 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.

2 participants