Animate 2D#

Display a labels layer above of an image layer using the add_labels and add_image APIs

Rendering frames...

  0%|          | 0/166 [00:00<?, ?it/s]IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1089, 630) to (1104, 640) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).

  1%|          | 1/166 [00:00<00:25,  6.41it/s]
  3%|▎         | 5/166 [00:00<00:07, 20.48it/s]
  5%|▌         | 9/166 [00:00<00:05, 27.51it/s]
  8%|▊         | 14/166 [00:00<00:04, 32.54it/s]
 11%|█         | 18/166 [00:00<00:04, 34.79it/s]
 13%|█▎        | 22/166 [00:00<00:04, 35.62it/s]
 16%|█▌        | 26/166 [00:00<00:03, 35.88it/s]
 18%|█▊        | 30/166 [00:00<00:03, 35.49it/s]
 20%|██        | 34/166 [00:01<00:04, 30.45it/s]
 23%|██▎       | 38/166 [00:01<00:04, 26.46it/s]
 25%|██▍       | 41/166 [00:01<00:05, 24.71it/s]
 27%|██▋       | 44/166 [00:01<00:05, 22.63it/s]
 28%|██▊       | 47/166 [00:01<00:05, 21.82it/s]
 30%|███       | 50/166 [00:01<00:05, 21.29it/s]
 32%|███▏      | 53/166 [00:02<00:05, 21.48it/s]
 34%|███▎      | 56/166 [00:02<00:05, 21.19it/s]
 36%|███▌      | 59/166 [00:02<00:05, 20.96it/s]
 37%|███▋      | 62/166 [00:02<00:04, 20.81it/s]
 39%|███▉      | 65/166 [00:02<00:04, 20.59it/s]
 41%|████      | 68/166 [00:02<00:04, 20.50it/s]
 43%|████▎     | 71/166 [00:02<00:04, 20.25it/s]
 45%|████▍     | 74/166 [00:03<00:04, 19.63it/s]
 46%|████▋     | 77/166 [00:03<00:04, 19.74it/s]
 48%|████▊     | 80/166 [00:03<00:04, 19.98it/s]
 50%|█████     | 83/166 [00:03<00:04, 20.13it/s]
 52%|█████▏    | 86/166 [00:03<00:03, 20.25it/s]
 54%|█████▎    | 89/166 [00:03<00:03, 20.34it/s]
 55%|█████▌    | 92/166 [00:03<00:03, 21.31it/s]
 57%|█████▋    | 95/166 [00:04<00:03, 22.20it/s]
 59%|█████▉    | 98/166 [00:04<00:02, 23.09it/s]
 61%|██████    | 101/166 [00:04<00:02, 23.69it/s]
 63%|██████▎   | 104/166 [00:04<00:03, 16.03it/s]
 64%|██████▍   | 107/166 [00:04<00:03, 17.82it/s]
 66%|██████▋   | 110/166 [00:04<00:02, 19.58it/s]
 68%|██████▊   | 113/166 [00:05<00:02, 20.90it/s]
 70%|██████▉   | 116/166 [00:05<00:02, 22.17it/s]
 72%|███████▏  | 119/166 [00:05<00:02, 22.99it/s]
 73%|███████▎  | 122/166 [00:05<00:01, 23.00it/s]
 75%|███████▌  | 125/166 [00:05<00:01, 23.70it/s]
 77%|███████▋  | 128/166 [00:05<00:01, 24.11it/s]
 79%|███████▉  | 131/166 [00:05<00:01, 24.09it/s]
 81%|████████  | 134/166 [00:05<00:01, 24.50it/s]
 83%|████████▎ | 137/166 [00:05<00:01, 24.46it/s]
 84%|████████▍ | 140/166 [00:06<00:01, 24.85it/s]
 86%|████████▌ | 143/166 [00:06<00:00, 24.97it/s]
 88%|████████▊ | 146/166 [00:06<00:00, 25.19it/s]
 90%|████████▉ | 149/166 [00:06<00:00, 25.00it/s]
 92%|█████████▏| 152/166 [00:06<00:00, 25.57it/s]
 94%|█████████▍| 156/166 [00:06<00:00, 27.52it/s]
 96%|█████████▋| 160/166 [00:06<00:00, 29.26it/s]
 99%|█████████▉| 164/166 [00:06<00:00, 29.88it/s]
100%|██████████| 166/166 [00:07<00:00, 23.71it/s]

from skimage import data
from scipy import ndimage as ndi
from napari_animation import Animation
import napari


blobs = data.binary_blobs(length=128, volume_fraction=0.1, n_dim=3)
viewer = napari.Viewer()
viewer.add_image(blobs.astype(float), name="blobs")
labeled = ndi.label(blobs)[0]
viewer.add_labels(labeled, name="blob ID")

animation = Animation(viewer)
viewer.update_console({"animation": animation})

animation.capture_keyframe()
viewer.camera.zoom = 0.2
animation.capture_keyframe()
viewer.camera.zoom = 10.0
viewer.camera.center = (0, 40.0, 10.0)
animation.capture_keyframe()
viewer.dims.current_step = (60, 0, 0)
animation.capture_keyframe(steps=60)
viewer.dims.current_step = (0, 0, 0)
animation.capture_keyframe(steps=60)
viewer.reset_view()
animation.capture_keyframe()
animation.animate("animate2D.mp4", canvas_only=False)

Total running time of the script: (0 minutes 12.618 seconds)

Gallery generated by Sphinx-Gallery