Repository navigation
create_label_zarrs: convert page 1 of a multi-page TIFF explicitly, and say so (fixes #1738) - #1889
Merged
Merged
Conversation
…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]>
|
@Sartoshirelli is attempting to deploy a commit to the scroll Team on Vercel. A member of the Team first needs to authorize it. |
1 task
1 task
1 task
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.
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_imageonmain), 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 logshas 5 pages; converting page 1 only (pages 2-5 are ignored). The new tests are exactly that run: againstmainthey fail on(5, 20) != (20, 30); on the branch they pass.Before:
_normalize_to_2dsqueezes then takesimage[..., 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_imageopens the TIFF withTiffFile, and if it has more than one page readspages[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 whatimreaddid) and a single-page JPEG case is asserted silent and shape-identical. Againstmainthe striped test fails on shape(5, 20) != (20, 30), so it pins #1738.tests/ink_detection/test_label_zarr_preprocessing.py: 23 passed; wholetests/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.
(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
maincopy (vesuvius/src/vesuvius/ink_detection/preprocessing/create_label_zarrs.py) is touched; themerge-ink-pipelinescopy is a separate branch.🤖 Generated with Claude Code