Skip to content

volume: the paper's automatic seeding for GenSeg (P6 part 1): cvc::gradient_vector_diffusion, seed_mode::critical_points, critical_point_seeds - #1291

Closed
transfix wants to merge 6 commits into
masterfrom
p6/paper-mode-core
Closed

transfix wants to merge 6 commits into
masterfrom
p6/paper-mode-core

Conversation

@transfix

Copy link
Copy Markdown
Owner

P6 part 1 of docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md (§5 steps 3-4): GenSeg's automatic seeding as the paper describes it (Bajaj, Yu and Auer, JSB 2003). It diffuses the gradient field and seeds the feature and background classes from its critical points. The default stays local_maxima; §5 step 5 decides the switch later.

What lands

  • cvc::gradient_vector_diffusion (inc/cvc/volume/gradient_vector_diffusion.h): SegMed's gvfflow, the paper's Eqs. 2-3, as a shared sliced stepper. A unit is one voxel update. It comes with gradient_vector_diffusion_job and a parameter table (iterations, k, weights, normalize).
    • weights picks the field the angles come from: current (the field being diffused, as the paper and SecStruct do) or initial (SegMed's).
    • cvc::critical_point_at classifies a voxel with SegMed's 26-neighbour test.
    • The stepper is shared for SecStruct, SegMonomer and the §2.3 skeletons.
  • seed_mode::critical_points (inc/cvc/volume/segmentation.h): the critical points of the diffused field become two classes after the point classes, feature (maxima) and background (minima).
    • The paper's §4 thresholds reclassify them (cp_feature_threshold, cp_background_threshold).
    • SegMed's choices are parameters: cp_field (image, the paper's f = I; or gradient_magnitude, SegMed's), cp_weights and cp_sample (SegMed's 1-in-21 thinning; 0 keeps every critical point).
    • Diffusion is set by cp_iterations and cp_k.
    • The seeds are placed in genseg_context's seeding phase, before the user's seeds, which win a shared voxel. The point classes may be empty.
  • cvc::critical_point_seeds, critical_point_seeds_stepper and critical_point_seeds_job: the seeds alone, as point_classes, with a sliced seeding phase.
  • param_table: enum names also read with - for _ (critical-points).
  • SegMed audit (roadmap §1.3 table and §5):
    • GVF_Compute returns at GVF.cpp:97 right after the initial field, so its diffusion, critical points and clustering never ran.
    • Segment ignores the critical list and marches from 13 voxels hard-coded for one heart dataset.
    • Other problems: 36 statics, exit()s in read_data and gvfflow, and write_data writing six fixed names into the current directory.
  • tools/volrover-goldens gets a segmed library: the dead code built with that early return patched out at configure time (as Skeletonization's patch is done), plus read_data's fopen "r" changed to "rb". It has four cases with goldens of the diffused field and the critical list.

Parity (T1)

critical_points_test's MatchSegMed runs SegMed's settings (cp_field = gradient_magnitude, cp_weights = initial, cp_sample = 20). The diffused field matches bit for bit, all 24000 components on each case. The critical lists match point for point, natively and under node:

Case Critical points (before thinning)
many_blobs 22 (41)
plateau 9 (12)
noisy_blob 12 (22)
noisy_slab 12 (23)

The legacy exp() is expf, so volrover goldens CI compares the field to 1e-6 on Linux. It compares the list byte for byte.

Tests (§1.7 rows)

  • gradient_vector_diffusion_test (11 tests):
    • Eq. 3 on one voxel by hand, in double;
    • fixed points and averages:
      • a zero field stays zero, and a uniform one is a fixed point;
      • with k = 0 a voxel takes its neighbours' mean;
    • the two weighting fields agreeing after one iteration and parting after more;
    • critical kinds on radial fields and saddles;
    • mirror invariance;
    • bad input, calls on separate threads, T7's resumable harness, units counted as voxel updates, cancelling;
    • the table.
  • critical_points_test (16 tests):
    • T1 above;
    • two blobs give a feature seed each;
    • segmenting with no point classes gives feature and background, and point classes add groups;
    • the §4 thresholds move seeds between the classes, also in data units;
    • thinning keeps a subset in order;
    • every voxel type gives the same seeds;
    • bad input, calls on separate threads, two cvc::apps in one process;
    • T7 on both steppers, with a step doing a bounded amount of work, cancelling;
    • the parameter table, including the hyphenated choice.
  • segmentation_test's six GenSeg goldens from P5 still match. Its ParameterTable test now expects the new fields and the third seed_mode choice.
  • T7's slowest step at budget 4096: 0.35-0.66 ms natively, 0.62-1.84 ms under node.

Both tests are in port_tests.cmake (the ports (wasm-mt, node) lane) and in SAN_CXX_TESTS. No CI job is added or renamed. ci.yml changes on one line and keeps its CRLF line endings.

Findings

  • SegMed differs from the paper in four ways:

    • it diffuses grad |grad I| where the paper takes f = I;
    • it takes angles from the initial field;
    • it keeps only minima above tlow;
    • it thins each run to one voxel in 21.

    All four are parameters: the defaults follow the paper, and SegMed's values reproduce SegMed.

  • The 26-neighbour test marks the whole 3x3x3 block around an extremum. SegMed's thinning keeps that block's first voxel, a corner. On a steep peak that corner's step cost is past MAX_TIME, so its front never moves. So the paper mode defaults to cp_sample = 0.

  • P5's "fronts stop at steep flanks" applies here too. On two sigma-2.5 blobs the feature class gets only the cores (123 voxels), and the background floods the rest. The default switch (§5 step 5) needs real maps and probably a rethink of gamma.

Rules

  • No singletons: no statics that write. tools/singleton_scan is unchanged, with no allowlist line.
  • No GPL or third-party code. The library reimplements SegMed's algorithm. The legacy sources are compiled only by tools/volrover-goldens, from a pinned volrover clone, and are never vendored.
  • git-clang-format was run on the changed lines only.

Next

Part 2 (stacked on this branch): segment.critical-points with -async / -start, cvc segment --automatic critical-points without a seeds file, pycvc critical_point_seeds, and #123's seed generators.

Refs #123.

…adient_vector_diffusion, seed_mode::critical_points, critical_point_seeds

Phase P6 of docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md (§5 steps 3-4), the core:

- cvc::gradient_vector_diffusion (inc/cvc/volume/gradient_vector_diffusion.h): SegMed's gvfflow
  (Eqs. 2-3 of Bajaj, Yu and Auer 2003) as a sliced stepper, a voxel update per unit, with its job
  and parameter table; the weighing field is a parameter (the field being diffused, the paper's
  and SecStruct's, or the initial one, SegMed's). cvc::critical_point_at classifies a voxel of a
  field by SegMed's 26-neighbour test. Shared, for SecStruct, SegMonomer and the §2.3 skeletons.
- seed_mode::critical_points: the critical points of the diffused gradient field as two classes
  after the point classes, "feature" (maxima) and "background" (minima), with the paper's §4
  thresholds (cp_feature_threshold, cp_background_threshold) and SegMed's choices as parameters
  (cp_field, cp_weights, cp_sample). They are seeded in genseg_context's "seeding" phase, before
  the user's seeds (which win a shared voxel); the point classes may be empty. The default stays
  local_maxima (§5 step 5 switches it later).
- cvc::critical_point_seeds, critical_point_seeds_stepper and critical_point_seeds_job.
- param_table: enum names also read with '-' for '_' (critical-points).
- SegMed audit in the roadmap's §1.3 table: GVF_Compute returns at GVF.cpp:97, so its diffusion
  and critical points never ran; Segment marches from 13 seeds hard-coded for one heart dataset.
- tools/volrover-goldens: a segmed library (the dead code built with the early return patched
  out), four cases, goldens of the critical list and the diffused field.

Tests (port_tests.cmake and SAN_CXX_TESTS): gradient_vector_diffusion_test (T2-T8) and
critical_points_test (T1: the field bit for bit and the critical lists point for point against
SegMed on all four cases; T3-T8). segmentation_test's six GenSeg goldens still match.
…s hidden until part 2

pycvc's %include of segmentation.h wrapped critical_point_seeds_job, whose
result_job<point_classes> SWIG could not name, and seeded_segmentation_params'
cp_weights, a diffusion_weights it knew nothing of. GCC and clang (tsan, ariglx-web)
failed on the generated code. pycvc_segmentation.i now includes
gradient_vector_diffusion.h for its enums and ignores critical_point_seeds, its stepper
and its job; part 2 wraps them.
transfix added a commit that referenced this pull request Nov 17, 2026
…ds, their DSL, CLI and pycvc surfaces, and VolUtils' seed generators (#1292)

Both parts of P6 (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md, section 5 steps 3-4) in one squash: #1292 was stacked on #1291 and carries its commits.

Part 1 (#1291): cvc::gradient_vector_diffusion (stepper, job, parameter table), critical_point_at, seed_mode::critical_points and critical_point_seeds (stepper, job), with SegMed goldens (T1), gradient_vector_diffusion_test, critical_points_test and the SegMed audit in the roadmap.

Part 2: segment.critical-points (-async, -start), cvc segment --automatic critical-points, pycvc critical_point_seeds(_job), and #123's capsid_critical_points and rotated_seeds (cvc capsid-seeds, cvc rotate-seeds, pycvc), with seed_generators_test.

No CI job added or renamed; ci.yml's SAN_CXX_TESTS line gains the three tests.

Refs #123.
@transfix

Copy link
Copy Markdown
Owner Author

Landed in master as part of #1292's squash (4268c0e): #1292 was stacked on this branch and carried all of its commits. This PR's last blocker was package-linux / libcvc-debug, which timed out twice on slow runners (every test about 2.4x slower than on #1292's run of the same code; open fixes for those timeouts: #1319, #1300).

@transfix transfix closed this Nov 17, 2026
auto-merge was automatically disabled November 17, 2026 07:21

Pull request was closed

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.

1 participant