Animate mixed#

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

/home/runner/work/napari-animation/napari-animation/examples/animateMixed.py:16: FutureWarning: `napari.view_image` is deprecated and will be removed in napari 0.7.0.
Use `viewer = napari.Viewer(); viewer.add_image(...)` instead.
  viewer = napari.view_image(blobs.astype(float), name="blobs")
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 (1086, 635) to (1088, 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).

  0%|          | 1/331 [00:00<01:21,  4.03it/s]
  2%|▏         | 5/331 [00:00<00:20, 16.00it/s]
  3%|▎         | 9/331 [00:00<00:13, 23.71it/s]
  4%|▍         | 13/331 [00:00<00:11, 28.78it/s]
  5%|▌         | 18/331 [00:00<00:09, 32.63it/s]
  7%|▋         | 22/331 [00:00<00:09, 33.69it/s]
  8%|▊         | 26/331 [00:00<00:08, 34.23it/s]
  9%|▉         | 30/331 [00:01<00:08, 34.14it/s]
 10%|█         | 34/331 [00:01<00:09, 30.09it/s]
 11%|█▏        | 38/331 [00:01<00:10, 26.91it/s]
 12%|█▏        | 41/331 [00:01<00:11, 25.39it/s]
 13%|█▎        | 44/331 [00:01<00:12, 23.31it/s]
 14%|█▍        | 47/331 [00:01<00:12, 22.80it/s]
 15%|█▌        | 50/331 [00:01<00:12, 22.28it/s]
 16%|█▌        | 53/331 [00:02<00:12, 22.52it/s]
 17%|█▋        | 56/331 [00:02<00:12, 22.16it/s]
 18%|█▊        | 59/331 [00:02<00:12, 21.95it/s]
 19%|█▊        | 62/331 [00:02<00:12, 21.51it/s]
 20%|█▉        | 65/331 [00:02<00:12, 21.41it/s]
 21%|██        | 68/331 [00:02<00:12, 21.46it/s]
 21%|██▏       | 71/331 [00:02<00:11, 22.09it/s]
 22%|██▏       | 74/331 [00:03<00:11, 21.83it/s]
 23%|██▎       | 77/331 [00:03<00:12, 20.99it/s]
 24%|██▍       | 80/331 [00:03<00:11, 21.12it/s]
 25%|██▌       | 83/331 [00:03<00:11, 21.30it/s]
 26%|██▌       | 86/331 [00:03<00:11, 21.13it/s]
 27%|██▋       | 89/331 [00:03<00:11, 21.25it/s]
 28%|██▊       | 92/331 [00:03<00:10, 22.41it/s]
 29%|██▊       | 95/331 [00:04<00:09, 23.69it/s]
 30%|██▉       | 98/331 [00:04<00:09, 24.62it/s]
 31%|███       | 101/331 [00:04<00:09, 25.35it/s]
 31%|███▏      | 104/331 [00:04<00:08, 26.04it/s]
 32%|███▏      | 107/331 [00:04<00:08, 26.58it/s]
 33%|███▎      | 110/331 [00:04<00:08, 26.64it/s]
 34%|███▍      | 113/331 [00:04<00:08, 26.74it/s]
 35%|███▌      | 116/331 [00:04<00:07, 26.99it/s]
 36%|███▌      | 119/331 [00:04<00:07, 26.94it/s]
 37%|███▋      | 122/331 [00:05<00:07, 26.15it/s]
 38%|███▊      | 125/331 [00:05<00:07, 26.35it/s]
 39%|███▊      | 128/331 [00:05<00:07, 26.77it/s]
 40%|███▉      | 131/331 [00:05<00:07, 26.88it/s]
 40%|████      | 134/331 [00:05<00:07, 26.84it/s]
 41%|████▏     | 137/331 [00:05<00:07, 26.62it/s]
 42%|████▏     | 140/331 [00:05<00:07, 27.03it/s]
 43%|████▎     | 143/331 [00:05<00:06, 27.03it/s]
 44%|████▍     | 146/331 [00:05<00:06, 26.86it/s]
 45%|████▌     | 149/331 [00:06<00:06, 26.46it/s]
 46%|████▌     | 152/331 [00:06<00:06, 27.06it/s]
 47%|████▋     | 156/331 [00:06<00:06, 28.31it/s]
 48%|████▊     | 159/331 [00:06<00:06, 28.55it/s]
 49%|████▉     | 163/331 [00:06<00:05, 29.51it/s]
 50%|█████     | 167/331 [00:06<00:08, 20.47it/s]
 51%|█████▏    | 170/331 [00:07<00:11, 14.22it/s]
 52%|█████▏    | 172/331 [00:07<00:13, 12.12it/s]
 53%|█████▎    | 174/331 [00:07<00:14, 10.73it/s]
 53%|█████▎    | 176/331 [00:07<00:15,  9.81it/s]
 54%|█████▍    | 178/331 [00:08<00:16,  9.17it/s]
 54%|█████▍    | 180/331 [00:08<00:17,  8.72it/s]
 55%|█████▍    | 181/331 [00:08<00:17,  8.57it/s]
 55%|█████▍    | 182/331 [00:08<00:17,  8.43it/s]
 55%|█████▌    | 183/331 [00:08<00:17,  8.46it/s]
 56%|█████▌    | 184/331 [00:08<00:17,  8.51it/s]
 56%|█████▌    | 185/331 [00:09<00:16,  8.73it/s]
 56%|█████▌    | 186/331 [00:09<00:16,  9.00it/s]
 57%|█████▋    | 188/331 [00:09<00:15,  9.52it/s]
 57%|█████▋    | 190/331 [00:09<00:13, 10.26it/s]
 58%|█████▊    | 192/331 [00:09<00:12, 10.96it/s]
 59%|█████▊    | 194/331 [00:09<00:11, 11.78it/s]
 59%|█████▉    | 196/331 [00:09<00:10, 12.65it/s]
 60%|█████▉    | 198/331 [00:10<00:09, 13.41it/s]
 60%|██████    | 200/331 [00:10<00:09, 13.98it/s]
 61%|██████    | 202/331 [00:10<00:09, 14.29it/s]
 62%|██████▏   | 204/331 [00:10<00:08, 14.57it/s]
 62%|██████▏   | 206/331 [00:10<00:08, 14.78it/s]
 63%|██████▎   | 208/331 [00:10<00:08, 14.87it/s]
 63%|██████▎   | 210/331 [00:10<00:08, 14.70it/s]
 64%|██████▍   | 212/331 [00:11<00:08, 14.65it/s]
 65%|██████▍   | 214/331 [00:11<00:08, 14.35it/s]
 65%|██████▌   | 216/331 [00:11<00:07, 14.50it/s]
 66%|██████▌   | 218/331 [00:11<00:07, 14.48it/s]
 66%|██████▋   | 220/331 [00:11<00:07, 14.58it/s]
 67%|██████▋   | 222/331 [00:11<00:07, 14.58it/s]
 68%|██████▊   | 224/331 [00:11<00:07, 14.64it/s]
 68%|██████▊   | 226/331 [00:12<00:07, 14.42it/s]
 69%|██████▉   | 228/331 [00:12<00:07, 14.49it/s]
 69%|██████▉   | 230/331 [00:12<00:07, 14.28it/s]
 70%|███████   | 232/331 [00:12<00:06, 14.19it/s]
 71%|███████   | 234/331 [00:12<00:06, 14.07it/s]
 71%|███████▏  | 236/331 [00:12<00:06, 14.05it/s]
 72%|███████▏  | 238/331 [00:12<00:06, 14.04it/s]
 73%|███████▎  | 240/331 [00:13<00:06, 14.02it/s]
 73%|███████▎  | 242/331 [00:13<00:06, 13.90it/s]
 74%|███████▎  | 244/331 [00:13<00:06, 13.88it/s]
 74%|███████▍  | 246/331 [00:13<00:06, 13.91it/s]
 75%|███████▍  | 248/331 [00:13<00:05, 13.87it/s]
 76%|███████▌  | 250/331 [00:13<00:05, 13.73it/s]
 76%|███████▌  | 252/331 [00:13<00:05, 13.72it/s]
 77%|███████▋  | 254/331 [00:14<00:05, 13.77it/s]
 77%|███████▋  | 256/331 [00:14<00:05, 13.58it/s]
 78%|███████▊  | 258/331 [00:14<00:05, 13.63it/s]
 79%|███████▊  | 260/331 [00:14<00:05, 13.53it/s]
 79%|███████▉  | 262/331 [00:14<00:05, 13.56it/s]
 80%|███████▉  | 264/331 [00:14<00:04, 13.49it/s]
 80%|████████  | 266/331 [00:14<00:04, 13.53it/s]
 81%|████████  | 268/331 [00:15<00:04, 13.50it/s]
 82%|████████▏ | 270/331 [00:15<00:04, 13.59it/s]
 82%|████████▏ | 272/331 [00:15<00:04, 13.59it/s]
 83%|████████▎ | 274/331 [00:15<00:04, 13.73it/s]
 83%|████████▎ | 276/331 [00:15<00:04, 13.71it/s]
 84%|████████▍ | 278/331 [00:15<00:03, 13.87it/s]
 85%|████████▍ | 280/331 [00:15<00:03, 13.96it/s]
 85%|████████▌ | 282/331 [00:16<00:03, 14.11it/s]
 86%|████████▌ | 284/331 [00:16<00:03, 14.14it/s]
 86%|████████▋ | 286/331 [00:16<00:03, 14.28it/s]
 87%|████████▋ | 288/331 [00:16<00:03, 14.16it/s]
 88%|████████▊ | 290/331 [00:16<00:02, 14.31it/s]
 88%|████████▊ | 292/331 [00:16<00:02, 14.36it/s]
 89%|████████▉ | 294/331 [00:16<00:02, 14.53it/s]
 89%|████████▉ | 296/331 [00:17<00:02, 14.58it/s]
 90%|█████████ | 298/331 [00:17<00:02, 14.61it/s]
 91%|█████████ | 300/331 [00:17<00:02, 14.53it/s]
 91%|█████████ | 302/331 [00:17<00:01, 14.53it/s]
 92%|█████████▏| 304/331 [00:17<00:01, 14.36it/s]
 92%|█████████▏| 306/331 [00:17<00:01, 14.26it/s]
 93%|█████████▎| 308/331 [00:17<00:01, 14.10it/s]
 94%|█████████▎| 310/331 [00:18<00:01, 14.05it/s]
 94%|█████████▍| 312/331 [00:18<00:01, 13.91it/s]
 95%|█████████▍| 314/331 [00:18<00:01, 13.85it/s]
 95%|█████████▌| 316/331 [00:18<00:01, 13.77it/s]
 96%|█████████▌| 318/331 [00:18<00:00, 13.46it/s]
 97%|█████████▋| 320/331 [00:18<00:00, 12.83it/s]
 97%|█████████▋| 322/331 [00:19<00:00, 11.97it/s]
 98%|█████████▊| 324/331 [00:19<00:00, 11.14it/s]
 98%|█████████▊| 326/331 [00:19<00:00, 10.34it/s]
 99%|█████████▉| 328/331 [00:19<00:00,  9.56it/s]
 99%|█████████▉| 329/331 [00:19<00:00,  9.16it/s]
100%|█████████▉| 330/331 [00:19<00:00,  8.80it/s]
100%|██████████| 331/331 [00:20<00:00,  8.54it/s]
100%|██████████| 331/331 [00:20<00:00, 16.49it/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.view_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 23.552 seconds)

Gallery generated by Sphinx-Gallery