Skip to content

Preprocessing: Spatial filtering

Biafra Ahanonu edited this page Jul 23, 2021 · 3 revisions

Please use the online documentation website going forward: https://bahanonu.github.io/ciatah/

Movie Filtering

This page documents different functions in the repository variable for filtering (spatial high/low/bandpass) movies to remove neuropil, cells, or other features.

options.freqLow = 1;
options.freqHigh = 4;
inputMovie = normalizeMovie(single(inputMovie),'normalizationType','lowpassFFTDivisive','freqLow',options.freqLow,'freqHigh',options.freqHigh,'waitbarOn',1,'bandpassMask','gaussian');

Images from unit test

Main filtering functions.

Below is a screen grab from a random frame using all the filtering functions. A nice way to quickly see the many differences between each functions filtering. image

Test function filtering

This is currently only for the Matlab fft, but I'll see about expanding to others. image

unitNormalizeMovie;

Matlab test function

  • I've also added the ability to test the parameter space of the Matlab fft, use the below command.
testMovieFFT = normalizeMovie(testMovie,'normalizationType','matlabFFT_test','secondaryNormalizationType','lowpassFFTDivisive','bandpassMask','gaussian','bandpassType','lowpass');
  • Should get a movie output similar to the below, where there is the original movie, the FFT movie, the original/FFT movie, and the dfof of original/FFT movie. image

Matlab test function movie output

Similar to above, showing results when using lowpassFFTDivisive normalization (matlab divide by lowpass before registering in modelPreprocessMovie and viewMovieRegistrationTest functions) with freqLow = 0 and freqHigh set to 1, 4, and 20. This corresponds to removing increasingly smaller features from the movie.

2014_04_01_p203_m19_check01_fft_example-3

ImageJ test function

To test the ImageJ FFT and determine the best parameters for a given set of movies, run the following function on a test movie matrix:

inputMovieTest = normalizeMovie(inputMovie,'normalizationType','imagejFFT_test');

The output should look like the below: image

Common Issues

A list of some common issues.

Dark halos around cells

If the spatial filter is not properly configured then dark halos will appear around high SNR cells, potentially obscuring nearby, low SNR cells. image

https://github.com/schnitzer-lab/miniscope_analysis/pull/30

  • FYI, for 4x downsampled movies, highFreq parameter of 4 (which corresponds to a fspecial gaussian with std of 4) produces the closest results to ImageJ Process->FFT->Bandpass Filter... with inputs of filter_large=10000 filter_small=80 suppress=None tolerance=5 (the current default in normalizeMovie).

  • Example frame from ImageJ and Matlab FFTs. image

  • Distribution of pixel differences between ImageJ and Matlab FFT movies. image

  • This matches the filter that ImageJ says it uses, which is fairly close to the Matlab filter. image

Example video: 2015_11_25_p384_m610_openfield01

  • Below is an example comparison using the following Matlab commands to produce the filtered inputs:
testMovieFFT = normalizeMovie(testMovie,'normalizationType','lowpassFFTDivisive','freqHigh',7);
testMovieFFTImageJ = normalizeMovie(testMovie,'normalizationType','imagejFFT');
diffMovie = testMovieFFT-testMovieFFTImageJ ;
  • With some tweaking of the freqHigh and other parameters, should hopefully be able to get closer to macheps and say that the two are identical for our purposes.

image

  • This is the histogram of the difference movie (Matlab - ImageJ). Notice most of the values are centered around zero with stdev ~0.2% df/f. image