Visualization Functions
Functions:
|
Crop an image around a centroid. |
|
Write a video clip to a file using imageio. |
|
Generate a grid movie from video instances. |
|
Generate and save grid movies for high-level states. |
|
Create a Sankey diagram representing the relationship between two sets of states. |
- state_moseq.viz.crop_image(image, centroid, crop_size)[source]
Crop an image around a centroid.
- Parameters:
image (Array) – Image to crop, shape (height, width, channels).
centroid (Tuple[int, int]) – (x, y) coordinates of the centroid.
crop_size (int | Tuple[int, int]) – Size of crop around centroid (int or (width, height)).
- Returns:
Cropped (and zero-padded if needed) image.
- Return type:
cropped_image
- state_moseq.viz.write_video_clip(frames, path, fps=30, quality=7)[source]
Write a video clip to a file using imageio.
- Parameters:
frames (Array) – Video frames of shape (n_frames, height, width, channels).
path (str) – Output file path.
fps (int) – Frames per second.
quality (int) – Video encoding quality.
- Return type:
None
- state_moseq.viz.grid_movie(instances, rows, cols, videos, centroids, window_size, max_duration=1200, dimming_factor=0.5)[source]
Generate a grid movie from video instances.
- Parameters:
instances (List[Tuple[str, int, int]]) – List of (key, start, end) tuples.
rows (int) – Number of rows in grid.
cols (int) – Number of columns in grid.
videos (Dict) – Dictionary of video readers keyed by name.
centroids (Dict[str, Float[Array, 'n_timesteps 2']]) – Dictionary of centroids for each frame.
window_size (int) – Size of cropped window around centroid.
max_duration (int) – Maximum duration of the grid movie.
dimming_factor (float) – Multiplicative factor for dimming after state instance has ended.
- Returns:
Combined movie frames as a single array.
- Return type:
frames
- state_moseq.viz.generate_grid_movies(states_dict, video_paths, centroids, output_dir='grid_movies', rows=3, cols=4, max_duration=1200, dimming_factor=0.25, quality=7, window_size=256)[source]
Generate and save grid movies for high-level states.
- Parameters:
states_dict (Dict[str, Int[Array, 'n_timesteps']]) – Dictionary of state sequences.
video_paths (Dict[str, str]) – Dictionary of paths to video files.
centroids (Dict[str, Float[Array, 'n_timesteps 2']]) – Dictionary of centroids for each frame.
output_dir (str) – Directory to save output movies.
rows (int) – Number of rows in each grid.
cols (int) – Number of columns in each grid.
max_duration (int) – Maximum duration of each movie.
dimming_factor (float) – Factor to dim frames after state instance has ended.
quality (int) – Video encoding quality.
window_size (int) – Size of window around centroid.
- Returns:
Sampled instances used for grid movies.
- Return type:
instances
- state_moseq.viz.plot_sankey(states_dict1, states_dict2)[source]
Create a Sankey diagram representing the relationship between two sets of states.
- Parameters:
states_dict1 (Dict[str, Int[Array, 'n_timesteps']]) – First dictionary of state sequences.
states_dict2 (Dict[str, Int[Array, 'n_timesteps']]) – Second dictionary of state sequences.
- Returns:
Plotly figure object containing the Sankey diagram.
- Return type:
fig