flatironinstitute / CaImAn

Computational toolbox for large scale Calcium Imaging Analysis, including movie handling, motion correction, source extraction, spike deconvolution and result visualization.
https://caiman.readthedocs.io
GNU General Public License v2.0
639 stars 370 forks source link

Poor outcome of PW-Rigid Motion Correction on 2P Data #1407

Open mohammadsohaib opened 2 months ago

mohammadsohaib commented 2 months ago

Your setup:

  1. Operating System (Linux, MacOS, Windows): Linux
  2. Hardware type (x86, ARM..) and RAM: x86 , 64gb
  3. Python Version (e.g. 3.9): 3.11
  4. Caiman version (e.g. 1.9.12): 1.11.2
  5. Which demo exhibits the problem (if applicable):
  6. How you installed Caiman (pure conda, conda + compile, colab, ..): Custom installation (conda + compile)
  7. Details: Issue Description: I am encountering issues while running motion correction on my 2P imaging data using the pw-rigid method, as the results look worse than the original data. Previously, I attempted rigid correction, but it failed to produce satisfactory results, so I switched to pw-rigid. I have experimented with several parameter variations in pw-rigid, but the outcome remains suboptimal.

For validation, I have been analyzing both the maximum projection and correlation images as suggested in the demo. However, the motion-corrected images appear significantly degraded when compared to the original data.

I have attached a figure comparing the original and motion-corrected images, as well as a demo movie for reference.

Parameters Used: PW-Rigid parameters: image

Dataset-dependent parameters: Objective Zoom (1.5x) 20X lens, frame rate: 30, frame size: 512X512 I would appreciate any insights or suggestions on what might be causing this issue, and how to improve the motion correction process.

Thank you for your assistance.

image image

Link to the demo video: https://drive.google.com/file/d/1dC-sA7IWZwXLmfKHU2fP_mGZSqNFBUQN/view?usp=drive_link

pgunn commented 2 months ago

Thanks for providing a download link; we'll give it a look. I'm hoping this is something we can fix with different parameters.

kushalkolar commented 2 months ago

those strides look way too huge

mesmerize-core can help you determine optimal params in a more structured way: https://github.com/nel-lab/mesmerize-core

mohammadsohaib commented 2 months ago

@kushalkolar Thanks for the suggestion, I will look into mesmerise as well. I did start with a small stride value eg:48 and then increased it.

mohammadsohaib commented 1 month ago

@pgunn Could you provide any suggestions after reviewing the TIFF file? @kushalkolar mesmerize-core looks promising, however, i ran into an error while running the demo.

I ran some more experiments, and upon viewing the TIFF files, it appears that the algorithm did a good job. However, I am a bit puzzled as to why the local correlation and maximum projection still look poor.

I also conducted some tests of my own, mimicking the logic of CaImAn motion correction, albeit in a simpler manner (just for a sanity check of motion correction). Using a rigid template, I was able to achieve a pretty good result visualised with normalized cross-correlation. This kind of hints that the caiman rigid motion correction would/might do a satisfactory job as well. However, these local correlations graphs always look bad.