From 587b5eb0b12469de875951405c051e605710a926 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 06:43:35 +0000 Subject: [PATCH] Docs: thin stacks underestimate Z drift, in Fiji Fast4DReg too The docs said Z drift 'may not be found' on about 10 slices or fewer. Measured: it is underestimated, by a quarter to a half for beads and down to almost zero for smooth texture, and the original Fiji macro gives the same numbers on the same movies (0.02 / 0.74 / 0.99 for a true drift of 1 slice on smooth 10-slice, bead 10-slice and smooth 20-slice movies). The side view of a thin stack is a few rows tall; its fixed edges and Z profile pull the correlation peak towards zero. workflow.md explains it, with the table. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Scma6VXx7mT1FYsKmB1184 --- README.md | 7 ++++--- docs/troubleshooting.md | 10 ++++++---- docs/workflow.md | 20 +++++++++++++++++--- lc_tests/README.md | 3 ++- lc_tests/make_fixtures.py | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a8a985a..a83509c 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,10 @@ More in [the Python guide](docs/python.md). Once a release is on PyPI, Channel alignment works on a single timepoint. For a multichannel time-lapse, the drift is measured on the reference channel and the same correction is applied to every channel. -3. **Z drift needs enough slices.** Z drift is measured on side projections of - the stack. On stacks of about 10 slices or fewer it may not be found at - all; check the `dz` column of the drift table. +3. **Z drift needs enough slices.** Z drift is measured on a side view of the + stack. On stacks of about 10 slices or fewer it is underestimated, down to + almost zero for smooth, textured images; the original Fiji Fast4DReg gives + the same numbers. Check the `dz` column of the drift table. More in [Troubleshooting](docs/troubleshooting.md). diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 4eacfe8..d24f73a 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -39,10 +39,12 @@ settings. Try the `mean` projection (better for noisy images), time averaging, or a maximum expected drift a little above the real drift. -**The Z drift stays at 0 although the sample moves in Z.** The stack may have -too few slices: on about 10 slices or fewer, Z drift may not be measured. With -20 slices or more it is. Check that Z correction is ticked and that the axes -put Z where it is in the file. +**The Z drift is too small, or stays near 0, although the sample moves in Z.** +The stack may have too few slices: on about 10 slices or fewer, Z drift is +underestimated, down to almost zero for smooth images (Fiji Fast4DReg does the +same; see [Before you start](workflow.md#before-you-start)). With about 20 +slices it is measured correctly. Also check that Z correction is ticked and +that the axes put Z where it is in the file. **The corrected movie still drifts slowly (live samples).** Compare with the previous frame (`reference: previous`) instead of the first. diff --git a/docs/workflow.md b/docs/workflow.md index f2bb8e1..8130588 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -68,9 +68,23 @@ Fiji saves hyperstacks in the order T, Z, C, Y, X and leaves out the dimensions of size 1. If the axes do not match the image, Fast4DRegPy stops and tells you the image's shape. -**Z drift needs enough slices.** On stacks of about 10 slices or fewer, Z drift -may not be found at all (the `dz` column stays near 0). With 20 slices or -more it is measured reliably. +**Z drift needs enough slices.** Z drift is measured on a side view of the +stack (Z against X), stretched to a square and cross-correlated. On a thin +stack that view is only a few rows tall: its top and bottom edges and its +brightness profile along Z do not move with the drift, and a drift of one or +two slices replaces a large part of it. The estimate is then pulled towards +zero. On stacks of about 10 slices or fewer, Z drift is underestimated: by a +quarter to a half for sharp, scattered structures, down to almost zero for +smooth texture. With about 20 slices it is measured correctly. The original +Fiji Fast4DReg gives exactly the same numbers on such stacks; this is a +property of the method, not of the Python version. If you need Z correction, +acquire more slices, and check the `dz` column of the drift table. + +| Test movie, true Z drift 0, 1, 2, 1 slices | Fiji Fast4DReg | Fast4DRegPy | +|---|---|---| +| Smooth texture, 10 slices | 0, 0.02, 0.03, 0.02 | 0, 0.02, 0.03, 0.02 | +| Beads, 10 slices | 0, 0.74, 1.65, 0.74 | 0, 0.74, 1.65, 0.74 | +| Smooth texture, 20 slices | 0, 0.99, 1.99, 0.99 | 0, 0.99, 1.99, 0.99 | ## Running it in the notebook diff --git a/lc_tests/README.md b/lc_tests/README.md index ac7c6c0..51a1f4d 100644 --- a/lc_tests/README.md +++ b/lc_tests/README.md @@ -15,7 +15,8 @@ labconstrictor-tools test --module fast4dreg_lc_tools --cases cases.json `make_fixtures.py` writes four small images cut out of one random scene at known whole-pixel offsets (Y and X sizes differ, so an axis swap shows): a 2D and a 3D time-lapse, and a 2D and a 3D multichannel image. The 3D -images have 20 slices: with about 10, Fast4DRegPy does not measure the Z drift. +images have 20 slices: on 10, the Z drift of this smooth scene is measured +as almost zero (by Fiji Fast4DReg too). `cases.json` runs each tool on them and checks what the hosts rely on: the shape and type of the corrected image, the columns and rows of the drift diff --git a/lc_tests/make_fixtures.py b/lc_tests/make_fixtures.py index f3aaa74..9710424 100644 --- a/lc_tests/make_fixtures.py +++ b/lc_tests/make_fixtures.py @@ -62,7 +62,7 @@ def write(folder: Path) -> None: metadata={"axes": "TYX"}, ) - volume = scene((38, 96, 104), seed=2) # 20 slices: Z drift is not measured on ~10 + volume = scene((38, 96, 104), seed=2) # 20 slices: Z is underestimated on ~10 frames = [cut(volume, o, (20, 64, 72)) for o in TIME_Z_OFFSETS] tifffile.imwrite( folder / "drift_tzyx.tif",