Skip to content

CaImAn summary images bug #456

@h-mayorquin

Description

@h-mayorquin

Currently, CaImAn stores the image mean as the array b:

Extracted here:

def _summary_image_read(self):
"""Read summary image mean."""
if self._dataset_file["estimates"].get("b"):
FOV_shape = self._dataset_file["params"]["data"]["dims"][()]
b_sum = self._dataset_file["estimates"]["b"][:].sum(axis=1)
return np.array(b_sum).reshape(FOV_shape, order="F")

And assigned here:

self._image_mean = self._summary_image_read()
self._sampling_frequency = self._dataset_file["params"]["data"]["fr"][()]

However, the documentation states that b is the spatial factor of the background component in the two-photon CNMF decomposition (the corresponding temporal factor is f):

https://caiman.readthedocs.io/en/latest/Getting_Started.html#result-interpretation

Averaging b alone does not produce a meaningful summary image; even the mean background would require multiplying b by f and that is still missing the ROIs contribution.

In Suite2P, by contrast, the mean image is defined as the pixel-wise mean across all registered frames (see meanImg):

https://suite2p.readthedocs.io/en/latest/outputs.html

And is calculated in exactly that way:
https://github.com/MouseLand/suite2p/blob/ddb8efd2ea3bae6f9a3a9253dc0ac336cf8721b2/suite2p/detection/detect.py#L143-L146

So, the what we store in CaImAn as a summary image is at odds with what we store in Suit2p. They are not the same thing. Moreover, there is an equivalent quantity in CaImAn (that I am not sure how often is available), mn:

https://github.com/flatironinstitute/CaImAn/blob/881e627adf951dde25d3839953c98acf6b4adab0/caiman/summary_images.py#L756-L809

Because the main goal of this library is to write results to NWB, I would prefer to store mn whenever it is available and omit the mean image otherwise. I think this is better than saving a potentially misleading average of b.

Thoughts? Am I wrong?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions