Skip to content

feat: slice interpolation for missing sections (z-morph)#87

Open
FIrgolitsch wants to merge 3 commits intopr-a-build-toolingfrom
pr-3-slice-interpolation
Open

feat: slice interpolation for missing sections (z-morph)#87
FIrgolitsch wants to merge 3 commits intopr-a-build-toolingfrom
pr-3-slice-interpolation

Conversation

@FIrgolitsch
Copy link
Copy Markdown
Contributor

@FIrgolitsch FIrgolitsch commented Mar 17, 2026

Summary

Reconstruct a single missing serial section from its two neighbours using z-aware affine morphing (zmorph). An affine transform T between the two boundary planes is computed, then every output plane at fractional depth alpha is produced by warping the before-boundary by T**alpha and the after-boundary by T**(alpha-1) and cross-fading the two (scipy.linalg.fractional_matrix_power + SimpleITK). This matches the physical geometry of serial sectioning instead of producing a blurry mean.

Key design points

  • Single strategy. interpolate_z_morph is the default. interpolate_average / interpolate_weighted are retained only as explicit, user-requested baselines via --method.
  • Hard skip on gate failure. When boundary registration or NCC-improvement gates fail, the function returns (None, diagnostics) with a specific fallback_reason. The CLI then emits no zarr — the slot is left as a genuine gap rather than fabricated data. A manifest fragment and diagnostics JSON are still written so the failure surfaces in slice_config_final.csv and the final report.
  • Only single-slice gaps. Two or more consecutive missing slices carry insufficient information and are explicitly rejected.
  • NCC-based boundary selection via find_best_overlap_planes scans a window of candidate planes on each side and picks the pair with the best normalised cross-correlation before registration.
  • Pipeline integration. Produces per-slice JSON + manifest fragments; --finalise mode aggregates all fragments and updates slice_config.csvslice_config_final.csv with interpolated, interpolation_failed, interpolation_fallback_reason columns for use by the Nextflow pipeline (PR feat: updated Nextflow workflows with profiles, auto-assess, rehoming #102).

Files (4)

  • linumpy/stitching/interpolation.pyinterpolate_z_morph, interpolate_average, interpolate_weighted, find_best_overlap_planes, NCC / foreground-fraction quality gates, Gaussian-feather blending, fractional-affine helpers
  • scripts/linum_interpolate_missing_slice.py — CLI. Modes:
    • default: slice_before slice_after output — emit interpolated ome.zarr + diagnostics
    • --preview — render an XY/XZ preview PNG instead of writing a zarr
    • --finalise --slice_config_in --slice_config_out --fragments — merge per-slice fragments back into slice_config.csv
    • Tuning flags: --method {zmorph,average,weighted}, --blend_method {linear,gaussian}, --registration_metric {MSE,CC,MI}, --overlap_search_window, --min_overlap_correlation, --reference_slab_size, --min_foreground_fraction, --min_ncc_improvement
  • linumpy/tests/test_stitching_interpolation.py
  • scripts/tests/test_interpolate_missing_slice.py

See docs/SLICE_INTERPOLATION_FEATURE.md (PR #96) for the physical model and parameter tuning.

Dependencies

Stacked on PR #95 (build tooling). Paired with PR #102 (Nextflow integration) and PR #103 (slice_config.csv schema).

Copy link
Copy Markdown
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

I have a few questions on how it works. see comments below. Also a few changes requested.

Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread scripts/linum_interpolate_missing_slice.py Outdated
Comment thread scripts/linum_interpolate_missing_slice.py Outdated
Comment thread linumpy/stitching/interpolation.py Outdated
Copy link
Copy Markdown
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

Two additional comments on your latest changes. Some comments from previous review are not resolved yet. Take your time, I just want to make sure I'm not too much of a bottleneck.

Comment thread linumpy/stitching/interpolation.py Outdated
Comment thread scripts/linum_interpolate_missing_slice.py Outdated
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from c7164ee to cdfe817 Compare April 17, 2026 22:09
@FIrgolitsch FIrgolitsch changed the base branch from main to pr-a-build-tooling April 17, 2026 22:09
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from cdfe817 to 9507ca8 Compare April 17, 2026 22:15
@FIrgolitsch FIrgolitsch changed the title Add slice interpolation for missing and degraded tissue sections feat: slice interpolation for missing and degraded sections Apr 17, 2026
@FIrgolitsch FIrgolitsch changed the title feat: slice interpolation for missing and degraded sections feat: slice interpolation for missing sections (z-morph) Apr 17, 2026
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from 9507ca8 to d2df02e Compare April 23, 2026 19:43
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from d2df02e to a4fb97e Compare April 23, 2026 21:09
@FIrgolitsch FIrgolitsch force-pushed the pr-a-build-tooling branch 2 times, most recently from 82b44be to ce8e35d Compare April 23, 2026 21:23
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from a4fb97e to 43e4fda Compare April 23, 2026 21:23
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from 43e4fda to 61a3d52 Compare April 23, 2026 21:28
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