Skip to content
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

Wrap-safe transfer functions #175

Merged
merged 6 commits into from
Nov 9, 2024
Merged

Conversation

talonchandler
Copy link
Collaborator

@talonchandler talonchandler commented Sep 10, 2024

Fixes #152. Fixes #172.

This PR implements wrap-safe transfer functions. After this PR, undersampled data will not create wrapped transfer functions, which should address many of the reconstruction artifacts we've seen.

Before (e.g. phase transfer function with transverse and axial wrapping):
Screenshot 2024-09-09 at 8 10 36 PM

After:
Screenshot 2024-09-09 at 8 11 14 PM

A prerequisite for this PR is a clear set of transverse and axial Nyquist sampling rates.

This PR redefines the calculate_transfer_function call so it should Just Work (™). The old calls have been renamed to _calculate_wrap_unsafe_transfer_function. Better naming suggestions are welcome.

This PR implements these fixes for all of the transfer functions in the main branch:

  • Widefield fluorescence
  • 3D phase
  • 2D phase

Similar behavior for vector-optics transfer functions will follow in the vector-prototype branch.

Testing status I'm passing automated tests, and I've tested all of the example scripts with undersampled parameters to check for wrapping. @ziw-liu I would appreciate your help with testing on real data because your use cases helped us spot these artifacts.

@talonchandler talonchandler linked an issue Sep 10, 2024 that may be closed by this pull request
@talonchandler talonchandler marked this pull request as ready for review September 10, 2024 03:36
@ziw-liu ziw-liu added the enhancement New feature or request label Sep 10, 2024
@ziw-liu
Copy link
Contributor

ziw-liu commented Sep 25, 2024

Thanks @talonchandler. Due to confusion on my part in #152 (comment), I'm not able to spot obvious improvement in the 3D phase reconstruction I'm working on. However the result looks at least as good as before, and should now be more accurate.

@talonchandler
Copy link
Collaborator Author

Thanks for clearly documenting the rotation artifacts, @ziw-liu.

I still think this PR is a clear improvement, though it will only have significant effects for severely undersampled data. Still worth merging in my opinion.

@ziw-liu
Copy link
Contributor

ziw-liu commented Oct 8, 2024

I tested 2D phase reconstruction with this PR.

Phase transfer function before:

image

Phase transfer function after:

image

The wrapping is indeed fixed.

However, #172 remains an issue:

image

Edit: reconstruction here:

/hpc/projects/comp.micro/virtual_staining/datasets/iNeurons/20240416_Exp01_iN_day7_calcein_hoescht/1-reconstruction/template_iN_liveimage_2_phase2d_nowrap.zarr

@ziw-liu
Copy link
Contributor

ziw-liu commented Oct 8, 2024

Optional improvements: tests and type hints for the new functions.

@talonchandler talonchandler merged commit cbda81d into main Nov 9, 2024
3 checks passed
@ziw-liu ziw-liu deleted the wrap-safe-transfer-functions branch November 10, 2024 00:04
talonchandler added a commit that referenced this pull request Dec 18, 2024
* Bump torch to unpin numpy (#176)

* bump torch to unpin numpy

* add SPEC-0 conformant numpy requirement

* Bump torch to unpin numpy (#176)

* bump torch to unpin numpy

* add SPEC-0 conformant numpy requirement

* first-pass scripts

* cleanup greens

* clean transfer function support

* fix naming issue

* Wrap-safe transfer functions (#175)

* helper functions

* fluorescence wrap safety

* 3d phase wrap safety

* fix axial nyquist bug

* 2d phase wrap safety

* fix interaction between padding and wrap safety

* green's tensor surfaces

* dark theme default

---------

Co-authored-by: Ziwen Liu <[email protected]>
talonchandler added a commit that referenced this pull request Dec 22, 2024
* Phase reconstruction is invariant to voxel-size (#164)

* fix bug finding focus in stack with only one slice

* refactor for clarify

* formatting

* print -> warnings.warn

* test single-slice case

* fix test bugs

* z-scale-invariant test object

* no rescaling on output

* forward simulation takes a "brightness" - simulating real microscope

* fix example script

* add background parameter for fluorescence forward model

* test voxel-size invariance

* rename I_norm -> direct_intensity

* refactor to clarify discretization factor

* remove comment

* fix fluorescence example bug

* improved docsring

---------

Co-authored-by: Ivan Ivanov <[email protected]>

* poster scripting

* may 14 poster draft

* last-minute poster changes

* quick clearning

* checkpoint before svd refactor

* SVD refactor

* pass singular system

* update visualization script

* fix visualization script scaling

* correct phase recon regression, legacy recon assumes axially even green's function

* helper functions

* fluorescence wrap safety

* 3d phase wrap safety

* fix axial nyquist bug

* 2d phase wrap safety

* fix interaction between padding and wrap safety

* clean defaults

* refactor singular system computation

* remove accidental duplicate

* refactor visuals

* fix warnings from tensoring a tensor

* match defaults

* readme type

* handle napari dependency

* Revert "fix warnings from tensoring a tensor"

This reverts commit ca4e7c5.

* Reapply "fix warnings from tensoring a tensor"

This reverts commit 790df57.

* revive old version of greens tensor for backwards compatibility

* fix tests that fail because of napari on github

* wrap-safe vector transfer function

* sampling tests

* fourier-space oversampling

* better visualizations for debugging

* complex-valued napari visuals

* complex utils

* fix colormaps

* debugging coherent tfs

* formatting

* fix rotation matrices

* fix dc term

* cleaning up

* first-pass visuals checkpoint

* matplotlib visuals

* temporarily turn off rotations

* debugging progress

* example script to generate matplotlib tf figures

* add rose asset

* add all assets

* plot all stokes

* brighter plot for greens

* visual improvements

* revised rotation-symmetric Green's tensor

* ignore

* fix green's tensor units

* modify circular anisotropy gellman matrices so that all transfer function are hermitian

* improved matplotlib visuals

* clean up plotting script

* fix bug with 3x3 hardcoded shape

* update tf components

* minor reconstruction updates

* refactor greens tensor spectrum

* clean test script

* clean models

* simple memory reduction

* clean debug statements

* reorder svd for clean i/o

* invert phase contrast

* formatting

* padding warning

* revise visuals

* visual cleanup

* manage large reconstructions

* Transfer function visuals (#178)

* Bump torch to unpin numpy (#176)

* bump torch to unpin numpy

* add SPEC-0 conformant numpy requirement

* Bump torch to unpin numpy (#176)

* bump torch to unpin numpy

* add SPEC-0 conformant numpy requirement

* first-pass scripts

* cleanup greens

* clean transfer function support

* fix naming issue

* Wrap-safe transfer functions (#175)

* helper functions

* fluorescence wrap safety

* 3d phase wrap safety

* fix axial nyquist bug

* 2d phase wrap safety

* fix interaction between padding and wrap safety

* green's tensor surfaces

* dark theme default

---------

Co-authored-by: Ziwen Liu <[email protected]>

* matplotlib movie features

* cheaper default viz script

* move all visuals to /examples/visuals

* update examples/README to table

* typo

* update badges

* typo

* revise main README

* add 10-second slideshow

* Clean installation instructions

* cleanup vector model example

* minor cleanup

* remove matplotlib plot example

* edits to README

* clarify contrast mechanisms in README

* simplify example installation w/ `pip install waveorder[examples]`

* fix unintended diff

* clarify `examples/README.md`

* document 3d-to-2d transfer function

* test orthonormal bases

* fix accidental deletion

* add deprecation warnings

* remove plotting assets

* label transfer function and simulation axes

* guard type hint

* matplotlib visuals docs and type hints

* add type hints throughout models

* revert TYPE_CHECKING to strings

---------

Co-authored-by: Ivan Ivanov <[email protected]>
Co-authored-by: Ziwen Liu <[email protected]>
Co-authored-by: Shalin Mehta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Severe artifacts and blur in 2D phase reconstruction [Bug] Overlapping rings in phase transfer function
2 participants