from andi_datasets.models_phenom import models_phenom
utils_videos
Helpers for videos
play_video
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
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
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
func_poisson_noise ()
Applies poisson noise to an image.
This is a custom DeepTrack feature, and a helper function for transform_to_video
mask
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
transform_to_video
transform_to_video (trajectory_data, particle_props={}, optics_props={}, background_props={}, get_vip_particles=[], with_masks=False, save_video=False, path='', motion_blur_generator=None)
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 ’ : intIntensity variation of particles in subsequent frames given as standard deviation. ‘ z ’ : floatParticle 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 ’ : floatRefractive index of particle. |
optics_props | dict | {} | Dictionary containing the properties of microscope as keyword arguments. Valid keys are: ‘ NA ’: floatNumerical aperture of the microscope. ‘ wavelength ’ : floatWavelength of light in meters. ‘ resolution ’ : floatEffective pixel size of the camera in meters. ‘ magnification ’ : floatMagnification of the optical system. ‘ refractive_index_medium ’ : floatRefractive 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 ’ : intMean background intensity. ‘ backgound_std ’ : intStandard 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. |
|
motion_blur_generator | NoneType | None | |
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
Generating trajectories and passing them through transform_to_video
to generate videos
= models_phenom().single_state(N = 50, T = 100, L = 128, Ds = 1)
trajs_test, _ = transform_to_video(trajs_test,
video, masks =True,
with_masks=np.arange(55).tolist(),
get_vip_particles= {"z": 0},
particle_props = {"background_mean": 0,
background_props "background_std": 0},
= {'origin': [0,0,20,20]}) optics_props
Play generated video in jupyter notebook
play_video(video)
Plot the first frames of the video and the masks
= plt.subplots(1, 2, figsize=(10, 5))
fig, (ax1, ax2) = ax1.imshow(video[1], cmap="gray")
img2 "Frame 0")
ax1.set_title(1], cmap="gray")
ax2.imshow(masks["Mask 0") ax2.set_title(
Text(0.5, 1.0, 'Mask 0')
Overlay trajectories on the first frame of the video
=(5, 5))
plt.figure(figsize0], cmap="gray", zorder = -1)
plt.imshow(video[for traj in np.moveaxis(trajs_test, 0, 1):
1], traj[:,0], alpha=0.2)
plt.plot(traj[:,0,L); plt.ylim(0,L)
plt.xlim( plt.show()
Import TIFF video
import_tiff_video
import_tiff_video (tiff_file_path:str)
Import a TIFF video file as a NumPy array.
This function reads a multi-frame TIFF file and converts each frame into a NumPy array. All frames are stacked along a new axis, resulting in a 3D array if the frames are 2D (or a 4D array if the frames are 3D).
Type | Details | |
---|---|---|
tiff_file_path | str | File path of the TIFF video file. |
Returns | ndarray | A NumPy array containing the video frames stacked along a new axis. The shape of the array is (N, M, O, …) where N is the number of frames, and M, O, … are the dimensions of each frame. |