AllenInstitute / ophys_etl_pipelines

Pipelines and modules for processing optical physiology data
Other
9 stars 5 forks source link

Bring python-generated max projection images in-line with legacy max projection images #359

Closed danielsf closed 2 years ago

danielsf commented 3 years ago

Some of the scientists have expressed concern that the max projection images coming out of the modern (~ 2021) pipeline do not look like the max projection images coming out of the legacy pipeline. We should make a good-faith effort to bring the two in-line.

The code generating the modern max projection images is here

https://github.com/AllenInstitute/ophys_etl_pipelines/blob/main/src/ophys_etl/modules/suite2p_registration/__main__.py#L95-L112

and here

https://github.com/AllenInstitute/ophys_etl_pipelines/blob/main/src/ophys_etl/modules/suite2p_registration/utils.py#L6-L31

which appears to just apply np.arra(data, axis=0) to the movie data (i.e. for each pixel, take its maximum over time).

The legacy max projection code originates from here

http://stash.corp.alleninstitute.org/projects/OM/repos/aibs.transcode/browse/src/maximum_intensity_projection.cpp

and likely involves some series of median and Gaussian filters. From an email, the legacy max projection images which the scientists would like to see can be found

in an ophys_experiment_NNNNNNNNN folder, in the “processed” folder the file called “max_downsample_4Hz_0.png” is the old max projection.

Tasks

Validation

danielsf commented 3 years ago

Looking through the legacy code, I think what it did was:

1) For each frame, apply a median filter with a 3x3 kernel (i.e. assign each pixel the median value of the 3x3 grid of pixels centered on it) 2) Accumulate a naive maximum projection of the median filtered frames

There was an option in the legacy code for decimation (downsampling the videos in time), but it looks like it was run with a decimation rate of 1, meaning that the videos were taken at their native frame rate.

I will implement the scheme I described above and run it on movies for which we still have legacy max projections to see if the results look good enough for the scientists.

danielsf commented 3 years ago

I believe this is an accurate description of the algorithm.

Here is an example "just use np.max" maximum projection image 936500602_suite2p_maximum_projection.png

Here is the legacy maximum projection of the same experiment

936500602_maximum_projection.png

Here is what results from 1) downsampling the movie to 4 Hz 2) applying a median filter to every frame of the downsampled movie 3) running np.max on the median filtered frames from (2)

936500602_sfd_max.png

I'll generate a few more examples, but this looks close enough to the legacy maximum projection as makes no difference. I'll formalize this into something we can call as part of our LIMS pipeline and issue a PR.