Skip to content
Pat Gunn edited this page Nov 28, 2017 · 3 revisions

Loading movies

Movies can be loaded either individually or as a set.

To load a single movie:

import caiman as cm
single_movie = cm.load('example_movies/demoMovie.tif')
print(single_movie.shape)

To load multiple movies and display them in sequence:

import caiman as cm
file_names = ['example_movies/demoMovie.tif','example_movies/demoMovie.tif'] # for the sake of the example we repeat the same movie
movies_chained = cm.load_movie_chain(file_names)
print(movies_chained.shape)

One can specify several parameters while loading. For instance frame rate, or if only some portion of the movies needs to be loaded, and so on. Check the documentation.

Both functions returns a movie object. The movie object can also be constructed giving as input one 3D array (time x x_dimension x y_dimension). Example.

import caiman as cm
movie_random = cm.movie(np.random.random([1000,100,100]))

Saving movies

Movies can be saved in several different formats (.mat, .tif, .hdf5, etc). In order to save just call the save command with the appropriate file extension.

movie_random.save('movie_random.tif')

It is also possible to save in a memory mappable format. This is an advanced topic that is dealt with in the demos in the root folder.

Visualizing movies

One can very efficiently play movies with the play function. The play function has options to modulate the exposure, the magnification, the playing frame rate, and adding an offset (sometimes movies are too negative or too positive thus hindering good visualization)

Example:

movies_chained.play(gain = 2., magnification = 2, fr = 100)

Ways a movie can be visualized are, for instance:

import pylab as pl
pl.imshow(np.mean(movies_chained,0))
pl.imshow(np.std(movies_chained,0))
pl.plot(np.mean(movies_chained, axis = (1,2)))

In this sense it is also very convenient the correlation image

c_img = movies_chained.local_correlations(eight_neighbours = True, swap_dim = False)
pl.imshow(c_img)

For some types of files the tiff reader swaps a dimension, for unknown reasons. To fix this, you might need to use the parameter swap_dim, especially if the correlation image does not make any sense.

Manipulating movies

concatenation

Movie objects behave like a numpy array. They can be summed, multiplied, divided, etc... This behavior is very versatile. The are only a few functions that cannot be implemented as an array, for instance concatenation. For that operation there is a special function, cm.concatenate:

movies_chained = cm.concatenate([single_movie,single_movie] , axis = 0)

movie resizing

Sometime it is useful to downsample or upsample the movies across some dimensions. We have implemented an efficient way of doing so, based on the opencv library. Below an example putting it all together:

movies_chained = cm.concatenate([single_movie,single_movie] , axis = 1).resize(1,1,.5).play(gain = 2., magnification = 2, fr = 50)