movies module

Module for generating movies from 2p images

(c) 2015 C. Schmidt-Hieber GPLv3

movies.get_normbright(arr, mid=16.0)[source]

Create 3-point calibration curve. Returns 3 points of input brightness that will be mapped to 0, 0.5, and 1.0 output

Parameters:
  • arr (numpy.ndarray) – Frame that will be used for calibration
  • mid (float, optional) – Midpoint value scaling. Default: 16.0
Returns:

normcurve – 3 points of input brightness that will be mapped to 0, 0.5, and 1.0 output

Return type:

3-tuple of floats

movies.html_movie(fn)[source]

Converts an mp4 movie to an html tag containing the complete encoded movie

Parameters:fn (str) – Full path to movie file name
Returns:html_movie – An html tag containing the complete movie
Return type:str
movies.make_movie(tiff_trunk, out_file, fps, normbright=None, scalebarframe=None, verbose=False, scale=None, crf=30, ffmpeg='ffmpeg')[source]

Produce a movie from a directory with individual tiffs at given frame rate

Parameters:
  • tiff_trunk (str or np.ndarray) – File name filter (full path) used as input to ffmpeg (e.g. /home/cs/data/ChanA_0001_%04d.tif); or movie as np.ndarray of shape (nframes, nx, ny).
  • out_file (str) – Full path to movie file name
  • fps (float) – Acquisition rate of tiffs in frames per second
  • normbright (3-tuple of floats, optional) – Brightness adjustment curve; see get_normbright() for format
  • scalebarframe (str, optional) – Full path to png with scale bar
  • verbose (bool, optional) – Print progress of ffmpeg
  • scale (2-tuple of ints, optional) – Rescale movie to given width and height in pixels. Default: None
  • crf (int, optional) – crf value to be passed to ffmpeg. Default: 30
  • ffmpeg (str, optional) – Path to ffmpeg binary. Default: FFMPEG global variable
Returns:

html_movie – An html tag containing the complete movie

Return type:

str

movies.numpy_movie(fn)[source]

Converts a movie to a numpy array

Parameters:fn (str) – Full path to movie file name
Returns:array – Numpy array of shape (nframes, npixels_x, npixels_y)
Return type:numpy.ndarray
movies.save_scale_bar(png_name, scale_length_int, scale_length_px, xpx, ypx)[source]

Save a png with transparent background showing a white scale bar with white label that can be added to a movie.

Parameters:
  • png_name (str) – Full path to png file name
  • scale_length_int (int) – Scale bar length in specimen dimensions (e.g. um)
  • scale_length_px (int) – Scale bar length in pixels
  • xpx (int) – Image width in pixels
  • ypx (int) – Image height in pixels