Animate mixed#

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

Rendering frames...

  0%|          | 0/331 [00:00<?, ?it/s]IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1089, 661) to (1104, 672) 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).

  0%|          | 1/331 [00:00<00:59,  5.56it/s]
  2%|▏         | 6/331 [00:00<00:14, 23.18it/s]
  3%|▎         | 11/331 [00:00<00:09, 32.08it/s]
  5%|▍         | 16/331 [00:00<00:08, 37.82it/s]
  6%|▋         | 21/331 [00:00<00:07, 40.39it/s]
  8%|▊         | 26/331 [00:00<00:07, 42.00it/s]
  9%|▉         | 31/331 [00:00<00:07, 42.56it/s]
 11%|█         | 36/331 [00:01<00:08, 35.46it/s]
 12%|█▏        | 40/331 [00:01<00:08, 32.49it/s]
 13%|█▎        | 44/331 [00:01<00:09, 29.25it/s]
 15%|█▍        | 48/331 [00:01<00:10, 28.07it/s]
 15%|█▌        | 51/331 [00:01<00:10, 27.89it/s]
 16%|█▋        | 54/331 [00:01<00:10, 27.44it/s]
 17%|█▋        | 57/331 [00:01<00:10, 27.18it/s]
 18%|█▊        | 60/331 [00:01<00:10, 26.90it/s]
 19%|█▉        | 63/331 [00:02<00:10, 26.52it/s]
 20%|█▉        | 66/331 [00:02<00:10, 26.37it/s]
 21%|██        | 69/331 [00:02<00:10, 26.17it/s]
 22%|██▏       | 72/331 [00:02<00:09, 26.66it/s]
 23%|██▎       | 75/331 [00:02<00:09, 25.99it/s]
 24%|██▎       | 78/331 [00:02<00:09, 25.75it/s]
 24%|██▍       | 81/331 [00:02<00:09, 25.79it/s]
 25%|██▌       | 84/331 [00:02<00:09, 25.80it/s]
 26%|██▋       | 87/331 [00:03<00:09, 25.77it/s]
 27%|██▋       | 90/331 [00:03<00:09, 25.87it/s]
 28%|██▊       | 94/331 [00:03<00:08, 27.94it/s]
 30%|██▉       | 98/331 [00:03<00:07, 29.23it/s]
 31%|███       | 102/331 [00:03<00:07, 30.00it/s]
 32%|███▏      | 106/331 [00:03<00:07, 30.62it/s]
 33%|███▎      | 110/331 [00:03<00:07, 31.03it/s]
 34%|███▍      | 114/331 [00:03<00:06, 31.25it/s]
 36%|███▌      | 118/331 [00:04<00:06, 31.46it/s]
 37%|███▋      | 122/331 [00:04<00:06, 31.16it/s]
 38%|███▊      | 126/331 [00:04<00:06, 30.98it/s]
 39%|███▉      | 130/331 [00:04<00:06, 31.06it/s]
 40%|████      | 134/331 [00:04<00:06, 31.46it/s]
 42%|████▏     | 138/331 [00:04<00:06, 31.40it/s]
 43%|████▎     | 142/331 [00:04<00:06, 31.13it/s]
 44%|████▍     | 146/331 [00:04<00:06, 30.83it/s]
 45%|████▌     | 150/331 [00:05<00:05, 31.00it/s]
 47%|████▋     | 154/331 [00:05<00:05, 32.67it/s]
 48%|████▊     | 158/331 [00:05<00:05, 34.34it/s]
 49%|████▉     | 163/331 [00:05<00:04, 36.25it/s]
 50%|█████     | 167/331 [00:05<00:05, 27.55it/s]
 52%|█████▏    | 171/331 [00:05<00:08, 18.41it/s]
 53%|█████▎    | 174/331 [00:06<00:09, 16.03it/s]
 53%|█████▎    | 177/331 [00:06<00:10, 14.97it/s]
 54%|█████▍    | 179/331 [00:06<00:10, 14.76it/s]
 55%|█████▍    | 181/331 [00:06<00:10, 14.93it/s]
 55%|█████▌    | 183/331 [00:06<00:09, 15.02it/s]
 56%|█████▌    | 185/331 [00:07<00:09, 15.22it/s]
 56%|█████▋    | 187/331 [00:07<00:09, 15.64it/s]
 57%|█████▋    | 189/331 [00:07<00:08, 16.12it/s]
 58%|█████▊    | 191/331 [00:07<00:08, 16.44it/s]
 58%|█████▊    | 193/331 [00:07<00:08, 17.17it/s]
 59%|█████▉    | 195/331 [00:07<00:07, 17.89it/s]
 60%|█████▉    | 198/331 [00:07<00:07, 18.65it/s]
 60%|██████    | 200/331 [00:07<00:06, 18.93it/s]
 61%|██████    | 202/331 [00:07<00:06, 19.05it/s]
 62%|██████▏   | 204/331 [00:08<00:06, 19.12it/s]
 62%|██████▏   | 206/331 [00:08<00:06, 19.09it/s]
 63%|██████▎   | 208/331 [00:08<00:06, 19.26it/s]
 63%|██████▎   | 210/331 [00:08<00:06, 19.09it/s]
 64%|██████▍   | 212/331 [00:08<00:06, 19.33it/s]
 65%|██████▍   | 214/331 [00:08<00:06, 18.70it/s]
 65%|██████▌   | 216/331 [00:08<00:06, 18.46it/s]
 66%|██████▌   | 218/331 [00:08<00:06, 17.75it/s]
 66%|██████▋   | 220/331 [00:08<00:06, 17.47it/s]
 67%|██████▋   | 222/331 [00:09<00:06, 17.28it/s]
 68%|██████▊   | 224/331 [00:09<00:06, 17.25it/s]
 68%|██████▊   | 226/331 [00:09<00:06, 17.23it/s]
 69%|██████▉   | 228/331 [00:09<00:05, 17.44it/s]
 69%|██████▉   | 230/331 [00:09<00:05, 17.36it/s]
 70%|███████   | 232/331 [00:09<00:05, 17.74it/s]
 71%|███████   | 234/331 [00:09<00:05, 17.93it/s]
 71%|███████▏  | 236/331 [00:09<00:05, 18.02it/s]
 72%|███████▏  | 238/331 [00:09<00:05, 18.19it/s]
 73%|███████▎  | 240/331 [00:10<00:04, 18.26it/s]
 73%|███████▎  | 242/331 [00:10<00:04, 18.18it/s]
 74%|███████▎  | 244/331 [00:10<00:04, 17.80it/s]
 74%|███████▍  | 246/331 [00:10<00:04, 17.95it/s]
 75%|███████▍  | 248/331 [00:10<00:04, 17.91it/s]
 76%|███████▌  | 250/331 [00:10<00:04, 17.91it/s]
 76%|███████▌  | 252/331 [00:10<00:04, 17.80it/s]
 77%|███████▋  | 254/331 [00:10<00:04, 17.79it/s]
 77%|███████▋  | 256/331 [00:10<00:04, 17.80it/s]
 78%|███████▊  | 258/331 [00:11<00:04, 17.78it/s]
 79%|███████▊  | 260/331 [00:11<00:04, 17.63it/s]
 79%|███████▉  | 262/331 [00:11<00:03, 17.63it/s]
 80%|███████▉  | 264/331 [00:11<00:03, 17.54it/s]
 80%|████████  | 266/331 [00:11<00:03, 17.31it/s]
 81%|████████  | 268/331 [00:11<00:03, 17.19it/s]
 82%|████████▏ | 270/331 [00:11<00:03, 17.26it/s]
 82%|████████▏ | 272/331 [00:11<00:03, 17.15it/s]
 83%|████████▎ | 274/331 [00:11<00:03, 16.98it/s]
 83%|████████▎ | 276/331 [00:12<00:03, 16.82it/s]
 84%|████████▍ | 278/331 [00:12<00:03, 16.94it/s]
 85%|████████▍ | 280/331 [00:12<00:03, 16.89it/s]
 85%|████████▌ | 282/331 [00:12<00:02, 16.74it/s]
 86%|████████▌ | 284/331 [00:12<00:02, 16.75it/s]
 86%|████████▋ | 286/331 [00:12<00:02, 16.70it/s]
 87%|████████▋ | 288/331 [00:12<00:02, 16.75it/s]
 88%|████████▊ | 290/331 [00:12<00:02, 16.94it/s]
 88%|████████▊ | 292/331 [00:13<00:02, 16.90it/s]
 89%|████████▉ | 294/331 [00:13<00:02, 16.64it/s]
 89%|████████▉ | 296/331 [00:13<00:02, 16.71it/s]
 90%|█████████ | 298/331 [00:13<00:01, 16.58it/s]
 91%|█████████ | 300/331 [00:13<00:01, 16.64it/s]
 91%|█████████ | 302/331 [00:13<00:01, 16.74it/s]
 92%|█████████▏| 304/331 [00:13<00:01, 16.68it/s]
 92%|█████████▏| 306/331 [00:13<00:01, 16.74it/s]
 93%|█████████▎| 308/331 [00:14<00:01, 16.65it/s]
 94%|█████████▎| 310/331 [00:14<00:01, 16.40it/s]
 94%|█████████▍| 312/331 [00:14<00:01, 16.35it/s]
 95%|█████████▍| 314/331 [00:14<00:01, 16.37it/s]
 95%|█████████▌| 316/331 [00:14<00:00, 16.16it/s]
 96%|█████████▌| 318/331 [00:14<00:00, 15.93it/s]
 97%|█████████▋| 320/331 [00:14<00:00, 15.06it/s]
 97%|█████████▋| 322/331 [00:14<00:00, 14.35it/s]
 98%|█████████▊| 324/331 [00:15<00:00, 13.45it/s]
 98%|█████████▊| 326/331 [00:15<00:00, 12.65it/s]
 99%|█████████▉| 328/331 [00:15<00:00, 11.73it/s]
100%|█████████▉| 330/331 [00:15<00:00, 10.97it/s]
100%|██████████| 331/331 [00:15<00:00, 20.92it/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()

viewer.dims.ndisplay = 3
viewer.camera.angles = (0.0, 0.0, 90.0)
animation.capture_keyframe()
viewer.camera.zoom = 2.4
animation.capture_keyframe()
viewer.camera.angles = (-7.0, 15.7, 62.4)
animation.capture_keyframe(steps=60)
viewer.camera.angles = (2.0, -24.4, -36.7)
animation.capture_keyframe(steps=60)
viewer.reset_view()
viewer.camera.angles = (0.0, 0.0, 90.0)
animation.capture_keyframe()
animation.animate("animateMixed.mp4", canvas_only=False)

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

Gallery generated by Sphinx-Gallery