Skip to content

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

Open
FIrgolitsch wants to merge 1 commit into
pr-l-manual-alignfrom
pr-3-slice-interpolation
Open

feat: slice interpolation for missing sections (z-morph)#87
FIrgolitsch wants to merge 1 commit into
pr-l-manual-alignfrom
pr-3-slice-interpolation

Conversation

@FIrgolitsch

@FIrgolitsch FIrgolitsch commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Stacked PR 8/22 — review order: #115#97#98#99#100#101#108#106#107#87#116#110#111#40#112#113#117#118#120#121#122#123#124#125

Base: pr-l-manual-align. Retargets to main as upstream PRs merge.


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 (feat: updated Nextflow workflows with profiles, auto-assess, rehoming #108).

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 for the physical model and parameter tuning.

@CHrlS98 CHrlS98 left a comment

Copy link
Copy Markdown
Contributor

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

@CHrlS98 CHrlS98 left a comment

Copy link
Copy Markdown
Contributor

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 2 times, most recently from 43e4fda to 61a3d52 Compare April 23, 2026 21:28
@FIrgolitsch FIrgolitsch changed the base branch from pr-a-build-tooling to pr-l-manual-align April 27, 2026 23:36
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from 61a3d52 to d941b23 Compare April 29, 2026 19:39
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from d941b23 to df76137 Compare April 30, 2026 03:21
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from df76137 to 247fcc0 Compare April 30, 2026 03:26
@FIrgolitsch FIrgolitsch force-pushed the pr-3-slice-interpolation branch from 247fcc0 to e7894cc Compare April 30, 2026 03:51
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