Repository navigation
Add exact blockwise topological thinning and sheetness; shuffle block order - #102
Merged
Merged
Conversation
Port COSEM's blockwise Lee thinning (curve skeletons and medial surfaces) on scikit-image's BSD kernel: the re-check runs over 8 parity subfields of the dataset's voxel index and tests Euler invariance, so a pass of k iterations with a 48k+2 voxel halo matches thinning the whole volume. Blocks are skipped when nothing changed near them and retired once their faces are final. Objects are thinned as if alone and keep their IDs. Port COSEM's sheetness and thickness from the medial surface: the Hessian sheet measure over 12 scales on each object's own mask, thickness as twice the distance to another label, and each voxel's sheetness from its nearest medial-surface voxels by geodesic distance within its object.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #102 +/- ##
==========================================
+ Coverage 86.51% 87.71% +1.20%
==========================================
Files 27 29 +2
Lines 4048 4558 +510
==========================================
+ Hits 3502 3998 +496
- Misses 546 560 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
COSEM's central differences of central differences underestimate the Hessian below a blur of about 2 voxels, so sheets thinner than 3 voxels scored 0.3-0.5. The default now takes Gaussian derivatives at each scale (blurring to within a voxel of it, then a sigma-1 derivative kernel at each point), normalised by sigma squared per axis, with Frangi's noise constant, and skips scales under a voxel, where thin tubes look flat. hessian='cosem' keeps COSEM's.
Contiguous db.range partitions put a dataset's dense blocks together, so a few partitions ran long after the rest: on the c-elegans ER, 73 of 96 workers sat idle at the end of sheetness. Blocks are now shuffled by default (randomize was a no-op: repartition keeps order), and sheetness packs its geodesic step by each block's object voxels, heaviest first, with per-task priorities so the slowest blocks start first.
…ng and retirement Both sheetness steps now widen a block's read until its distances are exact, up to max_padding_voxels (default 128) per side, and raise past that. The fill step used to stop after three widenings and keep what it had; with every voxel exact, the always-zero Unreached Volume column is gone. A new thinning test checks that blocks are retired, copied and skipped as intended and still give the whole-volume result.
A block with object voxels but no medial-surface voxels returned nothing from the first step, so the second step costed it 0 and started it last. It now reports its object voxels. The README also notes that thinning works on the voxel grid, so it ignores anisotropy.
Skeletons and medial surfaces are a voxel thin, so in a 2x2x2 window the background always wins the mode: on a 256^3 crop of a real medial surface, mode kept no voxels at s1. Multiscale gets a nonzero_mode method, which takes each window's most common non-zero label, and topological-thinning's pyramid uses it.
Renames nonzero_mode to mode_suppress_zero, after neuclease's flat_mode_except_zero, and adds mean_suppress_zero: the mean of each window's non-zero voxels. With multiscale: true, sheetness pyramids its three volumes by it, so thin ER and the values on its medial surface survive the coarse levels undiluted, as volume rendering needs.
Instead of a fixed 128 voxels per side, a read widens while it fits in half its dask worker's memory limit (the machine's available memory outside a worker), from an estimate of each step's bytes per voxel. max_padding_voxels stays as an optional hard cap. The error says which limit was hit.
With reconstruction: true, sheetness labels every voxel within a medial-surface voxel's ball, of radius its distance to the edge of its object, and adds each object's reconstructed volume to the summary CSV. Such a ball holds only its object's voxels, so what the rebuild misses is detail the medial surface lost. It is drawn in the geodesic step, whose reads already reach every ball that reaches the block.
This reverts commit bc0e7d4.
Merged
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.
@stuarteberg
Summary
topological-thinning: blockwise Lee thinning to curve skeletons, or to medial surfaces withmedial_surface: true, for objects such as ER that span the volume, which per-objectskeletonizecan't hold in memory.SparkTopologicalThinning, whose own kernel derives from GPL Fiji code.iterations_per_passiterations with a 48k+2 voxel halo therefore matches whole-volume thinning. The re-check also tests Euler invariance, so no object loses its last voxel (scikit-image's can).sheetness: sheetness and thickness from the medial surfacetopological-thinningwrites, ported from COSEM'sSparkCurvatureandSparkCalculatePropertiesFromMedialSurface:max_padding_voxels, if set), and the run fails beyond that;hessian: cosemreproduce COSEM's; the defaults intentionally do not, so default values are not directly comparable with published COSEM results.hessian: exact) takes Gaussian derivatives at scales from one voxel up. COSEM's finite differences score sheets thinner than 3 voxels only 0.3-0.5; with Gaussian derivatives, synthetic sheets score about 0.7-0.87, tubes 4 or more voxels wide 0.12-0.16 and thinner ones up to 0.3.Skeletonize3D_on 680 random volumes, with the same iteration counts and the same blocks found independent; its Hessian matchesSparkCurvature.getCurvatureto within 1e-5 (the jar computes in float32).roiandmask, including blocks being skipped and retired; the Gaussian-derivative Hessian against scipy's filters; and sheetness failing when a read can't be made exact.compute_blockwise_partitionsare now shuffled, with a fixed seed, so a dataset's dense blocks no longer land on a few workers.randomizehad been off, and a no-op becauserepartitionkeeps order. Results are read back in block order, so outputs don't change.block_partitionsandcompute_partitions). On the jrc_c-elegans-dddpc-1 ER on 96 workers this took sheetness from 94 to 30 min with identical results: shuffling took its first step from 20.8 to 13.4 min, and heaviest-first its second from 73.1 to 16.7 min. Other commands were not timed.randomize=False), and multiscale is unchanged.multiscalegetsdownsample_method: mode_suppress_zero(each window's most common non-zero label, as neuclease'sflat_mode_except_zero) andmean_suppress_zero(the mean of its non-zero voxels).topological-thinning's pyramid uses the first: its output is a voxel thin, and on a 256³ crop of a real medial surface plain mode kept no voxels at s1.sheetnesspyramids its three volumes with the second.topological_thinning,geodesic), so installs need a rebuild.