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

Simulate rotation out of imaging plane with the Rotator #31

Merged
merged 24 commits into from
Dec 17, 2024

Conversation

lauraporta
Copy link
Member

@lauraporta lauraporta commented Dec 2, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
While working on finding the centre of rotation (see #30) I noticed that the rotating cells describe an ellipse and not a circle. This kind of artefact could be due to a mismatch between the plane of rotation and the imaging plane.
Therefore, to prove it I expand the Rotator class to create a new type of synthetic rotation movies.

rotation_out_of_plane

You can notice in the max projection image that the trajectory of the cells is elliptical as expected.

Works also for rotations out of plane in another orientation:
rotation_out_of_plane_plus_orientation

And with shifted center of rotation:
rotation_out_of_plane

This new feature could be described also as a "3D rotation".

I can now use the new Rotator to generate synthetic movies to build an improved derotation algorithm. It will come in a separate PR.

What does this PR do?
Further methods to Rotation class and related tests.
Renaming of classes:

  • basic_rotator -> line_scanning_microscope (sorry the diff shows as if it is a whole new class 😭)
  • test_finding_center_of_rotation_by_joining_two_pipelines -> test_finding_center_of_rotation

Moves functions to fit an ellipse to a dedicated module (fit_ellipse.py)

References

See #26 #27

How has this PR been tested?

Made parametrised tests

Is this a breaking change?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 83.46457% with 21 lines in your changes missing coverage. Please review.

Project coverage is 47.26%. Comparing base (c88975e) to head (4129dac).
Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
derotation/analysis/fit_ellipse.py 64.00% 18 Missing ⚠️
...tation/analysis/incremental_derotation_pipeline.py 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
+ Coverage   43.89%   47.26%   +3.36%     
==========================================
  Files           6        7       +1     
  Lines         631      677      +46     
==========================================
+ Hits          277      320      +43     
- Misses        354      357       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lauraporta lauraporta marked this pull request as ready for review December 9, 2024 19:33
Copy link
Member

@IgorTatarnikov IgorTatarnikov left a comment

Choose a reason for hiding this comment

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

Looks great!

Just a few comments here and there. I could use some more information on the construction of the homography_matrix, why that specific form? From my understanding the current implementation adds a scaling factor in the second dimension based on cos(rotation_plane_angle), is that correct?

Might also be nice to add "noise/simulated activity" to the bright/dim cell objects. Add a flat random noise to simulate shot noise and then an underlying "ground truth" activity as well! Understand that this is outside of the scope of this PR.

derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
tests/test_integration/test_rotation_out_of_plane.py Outdated Show resolved Hide resolved
derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
tests/test_integration/test_rotation_out_of_plane.py Outdated Show resolved Hide resolved
derotation/simulate/line_scanning_microscope.py Outdated Show resolved Hide resolved
examples/elliptical_rotations.py Show resolved Hide resolved
@lauraporta
Copy link
Member Author

I could use some more information on the construction of the homography_matrix, why that specific form? From my understanding the current implementation adds a scaling factor in the second dimension based on cos(rotation_plane_angle), is that correct?

Yes it is correct. Your comment makes me wonder if it is an overkill to use affine_transform and a 3x3 matrix given that the transformation is only on one of the dimensions... 🤔

Copy link
Member

@IgorTatarnikov IgorTatarnikov left a comment

Choose a reason for hiding this comment

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

Looks good 👍 LGTM!

@IgorTatarnikov IgorTatarnikov merged commit 78e4f7a into main Dec 17, 2024
15 checks passed
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