Helpers for videos



 play_video (video, figsize=(5, 5), fps=10)

Displays a stack of images as a video inside jupyter notebooks.

Type Default Details
video ndarray Stack of images.
figsize tuple (5, 5) Canvas size of the video.
fps int 10 Video frame rate.
Returns Video object Returns a video player with input stack of images.



 convert_uint8 (vid, with_vips=False)

Converts a stack of images in to 8bit pixel format.

This is a helper function for transform_to_video

Type Default Details
vid ndarray Stack of images.
with_vips bool False
Returns ndarray Image stack in 8bit.



 psf_width (NA=1.46, wavelength=5e-07, resolution=1e-07)

Computes the PSF full width at half maximum (FWHM).

This is a helper function for transform_to_video

Type Default Details
NA float 1.46 Numerical aperture.
wavelength float 5e-07 Wavelength.
resolution float 1e-07 Resolution of the camera.
Returns int PSF width in pixels.



 func_poisson_noise ()

Applies poisson noise to an image.

This is a custom DeepTrack feature, and a helper function for transform_to_video



 mask (circle_radius, particle_list=[])

Computes binary masks for particles in microscopy videos.

This is a custom DeepTrack feature, and a helper function for transform_to_video.




 transform_to_video (trajectory_data, particle_props={}, optics_props={},
                     background_props={}, get_vip_particles=[],
                     with_masks=False, save_video=False, path='')

Transforms trajectory data into microscopy imagery data.

Trajectories generated through phenomenological models in andi-datasets are imaged under a Fluorescence microscope to generate 2D timelapse videos.

Type Default Details
trajectory_data ndarray Generated through models_phenom. Array of the shape (T, N, 2) containing the trajectories.
particle_props dict {} Dictionary containing the properties of particles to be simulated as keyword arguments. Valid keys are:

particle_intensity’ : array_like[int, int]
Intensity distribution of particles within a frame given as mean and standard deviations.

intensity_variation’ : int
Intensity variation of particles in subsequent frames given as standard deviation.

z’ : float
Particle positions with respect to the focal plane in pixel units defined by the pixel size in optics_props. For example, particles will be at focus when z=0.

refractive_index’ : float
Refractive index of particle.
optics_props dict {} Dictionary containing the properties of microscope as keyword arguments. Valid keys are:

NA’: float
Numerical aperture of the microscope.

wavelength’ : float
Wavelength of light in meters.

resolution’ : float
Effective pixel size of the camera in meters.

magnification’ : float
Magnification of the optical system.

refractive_index_medium’ : float
Refractive index of the medium sorrounding the particles.

output_region’: array_like[int, int, int, int]
ROI of the image to output.
Given in the format : [x, y, x + width, y + height].
background_props dict {} Dictionary containing properties related to background intensity as keyword arguments. Valid keys are:

background_mean’ : int
Mean background intensity.

backgound_std’ : int
Standard deviation of the background intesity with subsequent frames of a video.
get_vip_particles list [] List of particles for which the masks are needed in the output.
with_masks bool False If True, particle masks are returned in the output along with the video.
If False (default), only the video is returned in the output.
save_video bool False If True, the generated video will be saved at the given path.
path str File path for saving the video, the path should be given along the video format.
For example: ‘path’ = ‘./video.mp4’ will save the video in the current folder.
Returns tuple | ndarray Output type I

If with_masks = True,
The function returns a tuple containing:
masks : ndarray
video : ndarray
Note: If get_vip_particles is a non-empty list, the masks will contain only the vip particle masks.

Output type II

If with_masks = False,
The function returns:
video : ndarray
Note: If get_vip_particles is a non-empty list, the first frame in the output will be the masks of the given vip particles in the first frame, else (default) the output will be a ndarray of just the video.

Usage example

Please check tutorials for more detailed examples

Import packages

from andi_datasets.models_phenom import models_phenom

Generating trajectories and passing them through transform_to_video to generate videos

trajs_test, _ = models_phenom().single_state(N = 50, T = 100, L = 128, Ds = 1)
video, masks = transform_to_video(trajs_test,
                                  particle_props = {"z": lambda: 0 + np.random.rand() * 1},
                                  background_props = {"background_mean": 0,
                                                      "background_std": 0}, 
                                 optics_props = {'origin': [0,0,20,20]})

Play generated video in jupyter notebook