Movie Filtering¶
This page documents different features and functions in the CIAtah repository variable for filtering (spatial high/low/bandpass) movies to remove neuropil, cells, or other features.
Why conduct spatial filtering?¶
Spatial filtering can have a large impact on the resulting cell activity traces extracted from the movies and can lead to erroneous conclusions if not properly applied during pre-processing.
For example, below are the correlations between all cell-extraction outputs from PCA-ICA, ROI back-application of ICA filters, and CNMF-e on a miniature microscope one-photon movie. As can be seen, especially in the case of ROI analysis, the correlation between the activity traces is rendered artificially high due to the correlated background noise. This is greatly reduced in many instances after proper spatial filtering.
Filtering movies with ciapkg.movie_processing.normalizeMovie
¶
Users can quickly filter movies using the ciapkg.movie_processing.normalizeMovie
function. See below for usage.
% Load the movie (be in TIF, HDF5, AVI, etc.). Change HDF5 input dataset name as needed.
inputMovie = ciapkg.io.loadMovieList('pathToMovie','inputDatasetName','/1');
% Set options for dividing movie by lowpass version of the movie
options.freqLow = 1;
options.freqHigh = 4;
options.normalizationType = 'lowpassFFTDivisive';
options.waitbarOn = 1;
options.bandpassMask = 'gaussian';
% Options for normal bandpass filter
options.freqLow = 10;
options.freqHigh = 50;
options.normalizationType = 'fft';
options.waitbarOn = 1;
options.bandpassMask = 'gaussian';
% Set additional common options
options.showImages = 0; % Set to 1 if you want to view
% Run analysis
inputMovie = ciapkg.movie_processing.normalizeMovie(single(inputMovie),'options',options);
If users set options.showImages = 0;
, then normalizeMovie
will update a figure containing both real and frequency space before and after the filter has been applied along with an example of the filter in frequency space. This allows users to get a sense of what their filter is doing. See below for examples.
FFT bandpass filtering¶
Bandpass filtering where only red
frequencies in filter
image (FFT of bottom left input image) are kept producing an image as in fft image
.
Divide by lowpass filtering¶
Another method is lowpassFFTDivisive
, which involves dividing the image by a lowpass version of itself. In the below example, the filter
image shows that only low frequencies will be kept. This will produce an image as in fft image
that when divided or subtracted from the input image
will produce difference
image.
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.
Test function filtering¶
This function will take a movie and conduct multiple spatial filtering operations on it then display for the user.
ciapkg.unit.unitNormalizeMovie;
After running that function, below is an example movie from a prefrontal cortex animal (miniature microscope, GCaMP) showing the difference in results with different spatial filtering.
Matlab test function¶
I've also added the ability to test the parameter space of the Matlab fft, use the below command.
testMovieFFT = ciapkg.movie_processing.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.
This can also be expanded to look at the effects of different spatial frequency filters on the resulting output, as indicated below.
Matlab test function movie output¶
Similar to above, showing results when using lowpassFFTDivisive
normalization (using the matlab divide by lowpass before registering
option 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.
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 = ciapkg.movie_processing.normalizeMovie(inputMovie,'normalizationType','imagejFFT_test');
The output should look like the below:
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.
- FYI, for 4x downsampled movies,
highFreq
parameter of 4 (which corresponds to afspecial
gaussian with std of 4) produces the closest results to ImageJProcess->FFT->Bandpass Filter...
with inputs offilter_large=10000 filter_small=80 suppress=None tolerance=5
(the current default inciapkg.movie_processing.normalizeMovie
).
Comparison of MATLAB and ImageJ FFT-based spatial filtering¶
- Example frame from ImageJ and Matlab FFTs.
- Distribution of pixel differences between ImageJ and Matlab FFT movies.
- This matches the filter that ImageJ says it uses, which is fairly close to the Matlab filter.
Example video: Basolateral amygdala miniature microscope imaging in open field
- Below is an example comparison using the following Matlab commands to produce the filtered inputs:
testMovieFFT = ciapkg.movie_processing.normalizeMovie(testMovie,'normalizationType','lowpassFFTDivisive','freqHigh',7);
testMovieFFTImageJ = ciapkg.movie_processing.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.
- 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.