Skip to content

create_label_zarrs: convert page 1 of a multi-page TIFF explicitly, and say so (fixes #1738) - #1889

Merged
bruniss merged 3 commits into
ScrollPrize:mainfrom
Sartoshirelli:label-zarrs-multipage
Oct 15, 2026
Merged

bruniss merged 3 commits into
ScrollPrize:mainfrom
Sartoshirelli:label-zarrs-multipage

Conversation

@Sartoshirelli

Copy link
Copy Markdown
Contributor

In one sentence: A multi-page label TIFF no longer turns into a label zarr whose height is the page count; the converter reads page 1 explicitly, warns that the other pages were ignored, and does the same on the tiled streaming path so both paths agree.

One real example: Starting with a 5-page label TIFF written the way an image editor exports a stack (the reproduction in #1738, run through convert_image on main), the converter produced a zarr of shape (5, 20) with no error; on this branch the same file produces the (20, 30) label from page 1 and logs has 5 pages; converting page 1 only (pages 2-5 are ignored). The new tests are exactly that run: against main they fail on (5, 20) != (20, 30); on the branch they pass.

Before: _normalize_to_2d squeezes then takes image[..., 0], which on a (pages, H, W) stack keeps the first column of each row: (2, H, W) → (2, H). Silent; surfaces later as a "data quality" problem in training.

After this PR: load_image opens the TIFF with TiffFile, and if it has more than one page reads pages[0] explicitly and warns ... has N pages; converting page 1 only. The tiled streaming path already converted page 1 only (asserted by an existing test); it now logs the same warning instead of being silent.

Proof: new tests convert a 5-page striped TIFF and a 5-page tiled TIFF and assert page 1 lands in level 0 with the right shape and the warning is logged; single-page inputs take the exact previous path (tif.asarray() is what imread did) and a single-page JPEG case is asserted silent and shape-identical. Against main the striped test fails on shape (5, 20) != (20, 30), so it pins #1738. tests/ink_detection/test_label_zarr_preprocessing.py: 23 passed; whole tests/ink_detection: 288 passed. Pyramidal TIFFs whose reduced levels sit in the IFD chain (subfiletype & 1) are not counted as extra pages.

Why / where this is useful: anyone making their own labels (the population from #1231) who exports a stack by accident. Option 1 from the issue (reject outright) is a one-line change if you prefer it; the explicit-first-page behaviour was chosen because it matches what the tiled path already does.

  • I personally verified that the example and proof above were produced by this PR on the stated data.
    (Left unchecked deliberately: the runs were executed by Claude Code on my own machine at my direction, not by my own hands. Every command, log, tag dump and hash is in the evidence branch so anyone can re-run them; I am the human answerable for this PR and will answer review here.)

Details

  • Only the main copy (vesuvius/src/vesuvius/ink_detection/preprocessing/create_label_zarrs.py) is touched; the merge-ink-pipelines copy is a separate branch.
  • Written by Claude Code and run on my machine at my direction; the numbers above are from those runs, not from memory.

🤖 Generated with Claude Code

…nd say so (fixes ScrollPrize#1738)

tifffile.imread stacks a multi-page TIFF into (pages, height, width) and
the channel squeeze in _normalize_to_2d then takes image[..., 0], so a
5-page 40x60 label became a (5, 40) zarr with no error.

load_image now opens the file with TiffFile and reads page 1 explicitly
when there is more than one page, logging which pages were ignored. The
tiled streaming path already converted page 1 only; it logs the same
warning instead of staying silent, so both paths agree. Single-page
input is read exactly as before.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown

@Sartoshirelli is attempting to deploy a commit to the scroll Team on Vercel.

A member of the Team first needs to authorize it.

@bruniss
bruniss merged commit ccb4318 into ScrollPrize:main Oct 15, 2026
18 of 19 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.

3 participants