neuroinformatics-unit / derotation

Derotate images acquired via 2-photon or 3-photon calcium imaging
BSD 3-Clause "New" or "Revised" License
7 stars 0 forks source link

Find centre of rotation (tentative 2) #30

Open lauraporta opened 4 days ago

lauraporta commented 4 days ago

Tentative 2 with squashed commits

Description

What is this PR

Why is this PR needed? See #12

What does this PR do?

Creates methods and pipeline to find the centre of rotation in the incremental dataset.

⚠️ It does not fix the wobbling issues. The pipeline works well with simulated data but worsens the real datasets.

Pipeline

Find the centre

Find the centre of rotation using the incremental rotations datasets, in which the sample was rotated at discrete angles with 10deg intervals. Centre of rotation is found by fitting an ellipse to the brightest ROI location at each of the 10deg configurations. New methods include:

ellipse_fit

max_projection_with_center

Use the new centre

In order to use the new centre of rotation, the derotate_an_image_array_line_by_line needed to be totally rewritten. I am discarding the usage of scipy.ndimage.rotate and using classic linear algebra to rotate the matrices. With this new implementation the derotation is so much faster! 🚀

How has this PR been tested?

The performance of the de-rotation when the centre of rotation is shifted has been tested with simulated data generated by the class Rotator.

I created a stepwise array of angles to imitate the incremental rotation dataset, and a sinusoidal array as the main experimental session dataset. rotation_angles

I then rotated a sample image that has two blobs that imitate two ROIs (one brighter than the other). test_image

Ellipse fit works well with a shifted centre: ellipse_fit

And derotation works smothly. This is the proof that in principle my derotation with shifted centres works.

I added tests to cover this new functionality and the pipeline.

Is this a breaking change?

No

Checklist:

lauraporta commented 4 days ago

From previous PR:

Improve tests, suggestions from @JoeZiminski in #25 :

codecov[bot] commented 4 days ago

Codecov Report

Attention: Patch coverage is 55.86207% with 64 lines in your changes missing coverage. Please review.

Project coverage is 43.98%. Comparing base (dd0bfab) to head (06623d7).

Files with missing lines Patch % Lines
...tation/analysis/incremental_derotation_pipeline.py 51.48% 49 Missing :warning:
derotation/analysis/full_derotation_pipeline.py 13.33% 13 Missing :warning:
derotation/derotate_by_line.py 90.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #30 +/- ## ========================================== - Coverage 48.54% 43.98% -4.56% ========================================== Files 5 6 +1 Lines 377 632 +255 ========================================== + Hits 183 278 +95 - Misses 194 354 +160 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.