open-ephys / OpenEphys.Bonsai.Miniscope

Bonsai package for controlling and acquiring data from head-borne miniscopes for calcium imaging.
https://open-ephys.github.io/miniscope-docs/index.html
0 stars 1 forks source link

Default FMP4 encoder is too lossey for downstream pipelines #8

Closed dprotter closed 1 week ago

dprotter commented 1 month ago

I and some other researchers have been recording miniscope data for a few weeks, and noticed when we began pre-processing data that we have unusual artifacts from the default FMP4 encoder. These appear as a grid of highly correlated pixels, and disrupt downstream data analysis. An example from caiman is below.

image

image

HFYU works in bonsai seems to introduce far fewer artifacts:

image

image

I propose having the default encoder be either a lossless encoder like "HFYU" or a raw encoder like "DIB ".

jonnew commented 1 month ago

I'm going to be honest, most of these don't look like cells but potentially autofluorescent blood vessels or some other artifact, in both scenarios.

Regardless, it is disturbing that the encoder does affect the results so much, whether the data is valid to begin with or not. I guess we should probably just default to no compression.

ChucklesOnGitHub commented 1 month ago

We were looking at encoding data in the same way the Miniscope-DAQ-qt software does a while back with @mgraupe using the FFMPeg VideoWriter node. To use the 8 bit gray format the Miniscope-DAQ-QT software does he used the command “-c: ffv1 -pix_fmt gray -bits_per_raw_sample 8”. We then found that FFMPeg running in the background was quite slow for long videos and that sometimes it would cause the task programmed in Bonsai to go indefinitely and then the resulting video files were corrupted. I would be keen on having a default recommendation to write miniscope data to file.

dprotter commented 1 month ago

@jonnew the cell-shaped stuff on the right image are definitely cells. High SNR, dont even need df/f to see most of them.The longer bands in the correlation image seem to be encoder artifacts.

image

rather than defaulting to "DIB " (uncompressed, I believe?) I think HFYU or getting instructions on troubleshooting FFMPEG to work for FFV1 would be more appropriate. the uncompressed files are just too large to realistically work with for people who do longitudinal imaging, in my opinion.

jonnew commented 1 month ago

Hi David, I'm not sure I agree with you. Can you image with uncompressed so we can take a look at those correlated areas? The degree of correlation might change a bit, which, again, is worrying, but they are not just going to turn into cells.

Assuming this is the case, the main issue is the signal itself.

Where are you imaging?