Skip to content

fix(ooc): skip the part of a partial edge tile past the image in the 2D out-of-core scan - #549

Open
darkclad wants to merge 3 commits into
PolusAI:mainfrom
darkclad:main-ooc-striped-tiff
Open

darkclad wants to merge 3 commits into
PolusAI:mainfrom
darkclad:main-ooc-striped-tiff

Conversation

@darkclad

@darkclad darkclad commented Nov 16, 2026 •

Copy link
Copy Markdown

Summary

Out of core, a 2D striped TIFF larger than 1024 pixels in either direction now gives the in-memory values. Nyxus reads such a file in 1024 x 1024 tiles. The tile buffer is always a full tile, and the strip loader writes only the part of a partial edge tile that lies inside the image, so the rest of the buffer still holds the previous tile's pixels and labels. The out-of-core scan in processNontrivialRois walked the whole buffer and took those cells as ROI pixels past the image's right or bottom edge:

  • Sums counted a ROI's pixels more than once. A 300 x 300 ROI of a striped 1200 x 1200 image had MEAN 2281.08 out of core against 649.5 in memory, with MIN and MAX unchanged.
  • Families that size a buffer from the ROI's box refused the run. The texture families, morphology, the moments, the radial distribution, the fractal dimension, Zernike and Gabor stopped with pixel (1224,100) lies outside the bounding box x 200..499, y 100..399 that sizes its buffer. Python raised RuntimeError; the command line wrote those features as 0.

Tiled TIFF files, and striped files of up to 1024 x 1024 pixels, were not affected.

The out-of-core scan now skips cells beyond the image's bounds, as the prescan, phase 1 and phase 2 scans already did. The strip loader also zero-fills the part of a partial edge tile past the image, so no reader of the buffer can find an earlier tile's pixels there. Every 2D tile scan now walks only a tile's in-image pixels, through one shared walker. In-memory values do not change.

Follow-ups are on Axle's PN Jira board (https://labshare.atlassian.net/jira/software/projects/PN/boards/851), which is where the PN keys below point. This closes PN-286 and PN-296.

Change

Two commits.

fix(ooc): skip the part of a partial edge tile past the image in the 2D out-of-core scan

  • src/nyx/phase3.cpp: the tile scan of processNontrivialRois skips a cell whose position is at or past the image's full width or height.
  • tests/python/test_2d_ooc_invariant.py: test_2d_ooc_2d_striped_over_one_tile_matches_in_ram_invariant writes a striped 1120 x 1080 image and a 64 x 64 tiled copy. The striped image is 2 x 2 tiles of 1024, with a 96-wide last column and a 56-high last row. It has three ROIs: one in the first tile, one across all four tiles, and one inside the partial corner tile. Every column of every ROI must agree between in memory, out of core, and the tiled copy out of core. It runs twice, once with *ALL_INTENSITY* and once with every 2D group. On the code before this change the intensity case fails on a value (MEAN 1858 against 464.5 on the first ROI), and the all-groups case fails on the outside the bounding box refusal.
  • Docs: large_images.rst no longer limits out-of-core equality to striped files of up to 1024 x 1024 pixels, and the tiles warning is gone. The memory-limit paragraph of troubleshooting.rst, the out-of-core rows of the 2D family pages, and the "Out-of-core ROIs of large striped TIFF files" entries of the intensity and intensity-histogram pages are updated to match.
  • tests/vetting/not_covered.md: the function count of test_2d_ooc_invariant.py.

fix(tiff): zero-fill partial strip tiles and walk only a tile's in-image pixels

  • src/nyx/grayscale_tiff.h: NyxusGrayscaleTiffStripLoader::loadTileFromFile sets the tile buffer to 0 before it fills a partial edge tile. This fixes the nested-ROI scan (nested_roi_py.cpp, PN-296), the one scan that walked the whole buffer without a bound. copyRow loses its "zero-fill" branch, which could never run.
  • src/nyx/volume_walk.h: Nyxus::walk_tile_pixels visits the pixels of one 2D tile that lie inside the image, row by row, with their buffer offset and image position. The prescan (slideprops.cpp), phase 1, phase 2 (2D and 2.5D), the out-of-core scan and the nested-ROI scan use it in place of a loop over every cell with a division and a bounds test per cell. ImageLoader1x gains get_full_width and get_full_height for the nested-ROI scan.
  • tests/test_2d_tiff_strip_loader_mechanics.h: the featurize-side loader checks cover the whole tile buffer and require the part past the image to be 0. On the loader before this change they fail at tile (0,1).
  • tests/python/test_2d_ooc_invariant.py: the striped test gains an anisotropic case (anisotropy_x=2, intensity and morphology). Every case also checks that its out-of-core runs took the out-of-core path: ROIs 2 and 3 are neighbors in memory, and out of core the neighbor features read 0. All three cases fail on the code before this PR.
  • docs/source/large_images.rst: the striped-image paragraph states what the test suite checks, in place of a one-off measurement.

Changed values

Out of core only; every in-memory value is unchanged. Python API, ram_limit=0 against 64 MB, intensity 1 + (x % 500) + 2 (y % 300).

Image, ROI Feature In memory Out of core, before Out of core, after
striped 1200 x 1200, 300 x 300 square MEAN 649.5 2281.08 649.5
striped 1200 x 1200, 300 x 300 square INTEGRATED_INTENSITY 5.8455e+07 2.05297e+08 5.8455e+07
striped 1200 x 1200, 300 x 300 square STANDARD_DEVIATION 193.649 3066.72 193.649
striped 1200 x 1200, 300 x 300 square ENERGY 4.13415e+10 1.47095e+11 4.13415e+10
striped 1200 x 1200, 300 x 240 ellipse MEAN 549.402 2197.61 549.402
striped 1200 x 1200, 300 x 240 ellipse STANDARD_DEVIATION 221.167 3325.99 221.167
striped 1120 x 1080, ROI in the first tile MEAN 464.5 1858 464.5
striped 1120 x 1080, ROI across four tiles MEAN 295.156 710.076 295.156
striped 1120 x 1080, ROI across four tiles STANDARD_DEVIATION 101.273 684.533 101.273

MIN and MAX were already correct. On both images, *ALL_GLCM*, *ALL_MORPHOLOGY* and GABOR raised the outside the bounding box error out of core before this change and now complete. After this change, all 738 columns of *ALL* other than the neighbour features match the in-memory run on every ROI of both images. A whole-image ROI of a 1200 x 1200 image of four quadrants (100, 1100, 2100, 3100), the example the intensity pages gave, now gives MEAN 1600 and IH_MAX_GRADIENT 360000 on both paths.

No oracle applies: this is an out-of-core == in-memory relation, and the in-memory values are vetted separately.

Testing

  • Full gtest suite (Windows, 1258 passed) and pytest tests/python/ on the whole directory: 330 passed. The 11 failures are the Arrow tests, which fail on this Arrow-less build with "Apache Arrow functionality is not available".
  • The new and extended tests fail on the code before this PR and pass after.
  • ASan + UBSan (Linux, gcc): gtest (1275 cases) and pytest tests/python/ -m "not arrow" through the bindings (330 passed), 0 sanitizer diagnostics.
  • check_coverage.py --check, check_test_names.py --check, every scan_*_coverage.py --check, the regenerated docs, and sphinx-build -W: clean.

Not in this PR, filed on the board:

  • PN-297: the out-of-core pass reads every tile of the slide once per oversized ROI.
  • PN-299: a tile read that throws inside the out-of-core loop leaves the ROI's pixel cloud and the image pair open.

The nested-ROI fix has no end-to-end test. Nested.find_relations relates every child to every parent whatever the geometry (PN-155), so a stray label in a ROI's box cannot change its output. The loader tests above cover the buffer the scan reads.

@vjaganat90 vjaganat90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I built the head and its base (2411943) and ran both:

  • The 1200 x 1200 striped table reproduces exactly. Out of core, the base gives MEAN 2281.08 and refuses *ALL_GLCM* with the outside the bounding box error; the head gives 649.5 and the in-memory GLCM_ASM_AVE.
  • In memory nothing moved: on four random images (striped 1300 x 1100, 1030 x 1500 and 500 x 333, tiled 700 x 900; 8 ROIs each), *ALL*, whole-slide and anisotropy_x=2 give the same 29,428 values on both.
  • Out of core, *ALL* on the two striped images over 1024 equals the in-memory run on the head (12,032 values, neighbor features aside); the base refuses both.

Nits

  • 9e8cf0b and 522e9bd are empty (each has its parent's tree), pushed only to re-run CI. I'd drop them before merge.

Demian Vladi added 2 commits November 20, 2026 12:35
…2D out-of-core scan

A striped TIFF is read in 1024 x 1024 tiles. The tile buffer is always a
full tile, and the strip loader writes only the part of a partial edge tile
that lies inside the image, so the rest still holds the previous tile's
pixels and labels. The out-of-core scan walked the whole buffer and took
those cells as pixels past the image's edge. On a striped image larger than
1024 pixels in either direction, the sums over a ROI counted its pixels up
to four times (MEAN 2281.08 against 649.5 in memory on a 300 x 300 ROI of a
1200 x 1200 image), and every family that sizes a buffer from the ROI's box
refused the run with "pixel ... lies outside the bounding box".

The out-of-core scan now skips cells beyond the image's bounds, as the
prescan, phase 1 and phase 2 scans do.

The new invariant test featurizes a striped 1120 x 1080 image, with ROIs in
the first tile, across all four tiles and inside the partial corner tile,
in memory and out of core, and a tiled copy out of core; every column must
agree, for the intensity features alone and for every 2D group.

The docs no longer limit out-of-core equality to striped files of up to
1024 x 1024 pixels: the tiles warning and the out-of-core rows and possible
issues of the 2D family pages are updated.
…age pixels

The strip loader reads a striped TIFF in 1024 x 1024 tiles into a buffer
that is always a full tile. It now sets the part of a partial edge tile
past the image to 0, so no reader of the buffer finds an earlier tile's
pixels or labels there. Before, only the scans that bounded themselves by
the image's size were safe; the nested-ROI scan was not.

The 2D tile scans (the prescan, phase 1, phase 2, the 2.5D scan, the
out-of-core scan and the nested-ROI scan) visit a tile's pixels through one
walker, Nyxus::walk_tile_pixels, which visits the part of the tile inside
the image row by row, instead of every cell of the buffer with a division
and a bounds test per cell.

The featurize-side strip loader tests check the whole tile buffer, with the
part past the image required to be 0; on the previous loader they fail at
tile (0,1). The striped out-of-core invariant adds a case with the image
resampled twice along x, and checks that its out-of-core runs took the
out-of-core path through the neighbor features, which that path leaves at 0.

large_images.rst states what the test suite checks on the striped image,
in place of a one-off measurement.
@darkclad
darkclad force-pushed the main-ooc-striped-tiff branch from 522e9bd to a5b47d6 Compare November 23, 2026 14:48
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