Skip to content

Fix 3D to 2D phase reconstruction #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
May 22, 2025
Merged

Fix 3D to 2D phase reconstruction #441

merged 48 commits into from
May 22, 2025

Conversation

talonchandler
Copy link
Collaborator

@talonchandler talonchandler commented Mar 7, 2025

Fixes ##172. Moved from old recOrder draft PR.

This PR fixes the 3D to 2D phase reconstruction, best demonstrated in this video with OPS006 data:

Screen.Recording.2025-05-07.at.5.38.07.PM.mov

phase-recon-comparison

The key fixes were:

  • rewriting the reconstruction with an SVD-based method, which synchronizes this code path with the rest of the waveorder framework. This allowed me to debug with easier math.
  • turning off the default background filter, which was too aggressive and accidentally suppressed the signals.

While debugging I made two observations:

  • the existing code only supported CLI reconstructions with data where the in-focus slice was in the central slice. For the OPS data, a single-slice offset of focus (25 um!) was enough to ruin the 3D-to-2D reconstruction. I added a new z_focus_offset parameter.
  • if the NA_illumination = NA_detection, the 3D-to-2D phase transfer function goes to zero. I need to think through it this makes sense, or if this is indicating a deeper modeling issue.

TODO:

  • save absorption to the output zarr, with correct channel names. I'm estimating absorption, just not saving it for now skipped for now...will reevaluate after testing with absorbing sample.
  • consider precalculating the SVD with the transfer function. The SVDs are reasonably large (a 2 x Z matrix needs an SVD for each X*Y pixel), so I expect this to be the bottleneck. DONE.

Paths:

  • /hpc/projects/comp.micro/microscope_dev/2025-3d-to-2d-debug/2025-05-07-3d-to-2d-debug/visualize.py will open napari like in the viewer above

@talonchandler talonchandler changed the title Debug 3D to 2D phase reconstruction Fix 3D to 2D phase reconstruction May 8, 2025
@talonchandler talonchandler marked this pull request as ready for review May 8, 2025 01:27
@ziw-liu ziw-liu added the bug Something isn't working label May 8, 2025
@ziw-liu
Copy link
Contributor

ziw-liu commented May 8, 2025

For the OPS data, a single-slice offset of focus (25 um!) was enough to ruin the 3D-to-2D reconstruction.

Does this mean that this method will be very sensitive to tilted sample? @ahillsley can confirm but I recall seeing some variation of focus within FOVs. Maybe they will need tiling here?

@talonchandler
Copy link
Collaborator Author

Maybe they will need tiling here?

Very possible. On our first few iterations we should definitely keep an eye on our reconstruction quality that varies with focus across the FOV.

@talonchandler talonchandler requested a review from ziw-liu May 21, 2025 23:01

Examples
--------
>>> _position_list_from_shape_scale_offset(5, 1.0, 0.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be moved to tests? We don't have doctest set up.

ziw-liu
ziw-liu previously approved these changes May 22, 2025
Copy link
Contributor

@ziw-liu ziw-liu left a comment

Choose a reason for hiding this comment

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

Great work!

@ziw-liu
Copy link
Contributor

ziw-liu commented May 22, 2025

This works much better with cellpose!
image
image

@talonchandler talonchandler merged commit d15b7b9 into main May 22, 2025
11 checks passed
@talonchandler talonchandler deleted the debug-3d-to-2d branch May 22, 2025 22:34
@ziw-liu ziw-liu added this to the waveOrder v3 milestones milestone May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants