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 (854, 626) to (864, 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:13,  4.47it/s]
  2%|▏         | 5/331 [00:00<00:19, 17.06it/s]
  3%|▎         | 9/331 [00:00<00:13, 24.63it/s]
  4%|▍         | 14/331 [00:00<00:10, 30.62it/s]
  6%|▌         | 19/331 [00:00<00:09, 33.92it/s]
  7%|▋         | 23/331 [00:00<00:08, 35.14it/s]
  8%|▊         | 27/331 [00:00<00:08, 35.69it/s]
  9%|▉         | 31/331 [00:01<00:08, 35.83it/s]
 11%|█         | 35/331 [00:01<00:10, 29.45it/s]
 12%|█▏        | 39/331 [00:01<00:11, 26.31it/s]
 13%|█▎        | 42/331 [00:01<00:11, 25.05it/s]
 14%|█▎        | 45/331 [00:01<00:12, 23.77it/s]
 15%|█▍        | 48/331 [00:01<00:12, 23.19it/s]
 15%|█▌        | 51/331 [00:01<00:12, 23.23it/s]
 16%|█▋        | 54/331 [00:02<00:12, 22.81it/s]
 17%|█▋        | 57/331 [00:02<00:12, 22.44it/s]
 18%|█▊        | 60/331 [00:02<00:12, 22.19it/s]
 19%|█▉        | 63/331 [00:02<00:12, 21.95it/s]
 20%|█▉        | 66/331 [00:02<00:12, 21.98it/s]
 21%|██        | 69/331 [00:02<00:11, 22.07it/s]
 22%|██▏       | 72/331 [00:02<00:11, 22.53it/s]
 23%|██▎       | 75/331 [00:03<00:11, 22.27it/s]
 24%|██▎       | 78/331 [00:03<00:11, 21.82it/s]
 24%|██▍       | 81/331 [00:03<00:11, 21.67it/s]
 25%|██▌       | 84/331 [00:03<00:11, 21.61it/s]
 26%|██▋       | 87/331 [00:03<00:11, 21.61it/s]
 27%|██▋       | 90/331 [00:03<00:11, 21.43it/s]
 28%|██▊       | 93/331 [00:03<00:10, 22.94it/s]
 29%|██▉       | 96/331 [00:03<00:09, 24.02it/s]
 30%|██▉       | 99/331 [00:04<00:09, 24.67it/s]
 31%|███       | 102/331 [00:04<00:08, 25.53it/s]
 32%|███▏      | 105/331 [00:04<00:08, 26.17it/s]
 33%|███▎      | 108/331 [00:04<00:08, 26.49it/s]
 34%|███▎      | 111/331 [00:04<00:08, 26.74it/s]
 34%|███▍      | 114/331 [00:04<00:08, 26.35it/s]
 35%|███▌      | 117/331 [00:04<00:08, 26.53it/s]
 36%|███▋      | 120/331 [00:04<00:07, 26.86it/s]
 37%|███▋      | 123/331 [00:04<00:07, 26.35it/s]
 38%|███▊      | 126/331 [00:05<00:07, 26.51it/s]
 39%|███▉      | 129/331 [00:05<00:07, 26.58it/s]
 40%|███▉      | 132/331 [00:05<00:07, 26.91it/s]
 41%|████      | 135/331 [00:05<00:07, 26.99it/s]
 42%|████▏     | 138/331 [00:05<00:07, 27.04it/s]
 43%|████▎     | 141/331 [00:05<00:07, 27.08it/s]
 44%|████▎     | 144/331 [00:05<00:06, 26.96it/s]
 44%|████▍     | 147/331 [00:05<00:06, 26.79it/s]
 45%|████▌     | 150/331 [00:05<00:06, 26.74it/s]
 47%|████▋     | 154/331 [00:06<00:06, 29.16it/s]
 48%|████▊     | 158/331 [00:06<00:05, 30.43it/s]
 49%|████▉     | 162/331 [00:06<00:05, 31.59it/s]
 50%|█████     | 166/331 [00:06<00:05, 32.74it/s]
 51%|█████▏    | 170/331 [00:06<00:10, 15.79it/s]
 52%|█████▏    | 173/331 [00:07<00:12, 12.87it/s]
 53%|█████▎    | 176/331 [00:07<00:13, 11.17it/s]
 54%|█████▍    | 178/331 [00:07<00:14, 10.44it/s]
 54%|█████▍    | 180/331 [00:08<00:15,  9.86it/s]
 55%|█████▍    | 182/331 [00:08<00:15,  9.48it/s]
 56%|█████▌    | 184/331 [00:08<00:15,  9.36it/s]
 56%|█████▌    | 186/331 [00:08<00:15,  9.57it/s]
 57%|█████▋    | 188/331 [00:09<00:14,  9.99it/s]
 57%|█████▋    | 190/331 [00:09<00:13, 10.48it/s]
 58%|█████▊    | 192/331 [00:09<00:12, 11.16it/s]
 59%|█████▊    | 194/331 [00:09<00:11, 11.86it/s]
 59%|█████▉    | 196/331 [00:09<00:10, 12.77it/s]
 60%|█████▉    | 198/331 [00:09<00:09, 13.50it/s]
 60%|██████    | 200/331 [00:09<00:09, 13.99it/s]
 61%|██████    | 202/331 [00:09<00:08, 14.43it/s]
 62%|██████▏   | 204/331 [00:10<00:08, 14.78it/s]
 62%|██████▏   | 206/331 [00:10<00:08, 14.76it/s]
 63%|██████▎   | 208/331 [00:10<00:08, 14.86it/s]
 63%|██████▎   | 210/331 [00:10<00:08, 14.31it/s]
 64%|██████▍   | 212/331 [00:10<00:08, 14.57it/s]
 65%|██████▍   | 214/331 [00:10<00:08, 14.49it/s]
 65%|██████▌   | 216/331 [00:10<00:08, 14.35it/s]
 66%|██████▌   | 218/331 [00:11<00:07, 14.22it/s]
 66%|██████▋   | 220/331 [00:11<00:08, 13.86it/s]
 67%|██████▋   | 222/331 [00:11<00:07, 13.86it/s]
 68%|██████▊   | 224/331 [00:11<00:07, 13.66it/s]
 68%|██████▊   | 226/331 [00:11<00:07, 13.67it/s]
 69%|██████▉   | 228/331 [00:11<00:07, 13.55it/s]
 69%|██████▉   | 230/331 [00:11<00:07, 13.59it/s]
 70%|███████   | 232/331 [00:12<00:07, 13.53it/s]
 71%|███████   | 234/331 [00:12<00:07, 13.21it/s]
 71%|███████▏  | 236/331 [00:12<00:07, 13.16it/s]
 72%|███████▏  | 238/331 [00:12<00:06, 13.57it/s]
 73%|███████▎  | 240/331 [00:12<00:06, 13.69it/s]
 73%|███████▎  | 242/331 [00:12<00:06, 14.00it/s]
 74%|███████▎  | 244/331 [00:13<00:06, 14.04it/s]
 74%|███████▍  | 246/331 [00:13<00:05, 14.19it/s]
 75%|███████▍  | 248/331 [00:13<00:05, 14.13it/s]
 76%|███████▌  | 250/331 [00:13<00:05, 14.24it/s]
 76%|███████▌  | 252/331 [00:13<00:05, 14.09it/s]
 77%|███████▋  | 254/331 [00:13<00:05, 13.91it/s]
 77%|███████▋  | 256/331 [00:13<00:05, 13.61it/s]
 78%|███████▊  | 258/331 [00:14<00:05, 13.54it/s]
 79%|███████▊  | 260/331 [00:14<00:05, 13.46it/s]
 79%|███████▉  | 262/331 [00:14<00:05, 13.60it/s]
 80%|███████▉  | 264/331 [00:14<00:05, 13.19it/s]
 80%|████████  | 266/331 [00:14<00:04, 13.29it/s]
 81%|████████  | 268/331 [00:14<00:04, 13.00it/s]
 82%|████████▏ | 270/331 [00:14<00:04, 13.24it/s]
 82%|████████▏ | 272/331 [00:15<00:04, 13.30it/s]
 83%|████████▎ | 274/331 [00:15<00:04, 13.37it/s]
 83%|████████▎ | 276/331 [00:15<00:04, 13.20it/s]
 84%|████████▍ | 278/331 [00:15<00:03, 13.40it/s]
 85%|████████▍ | 280/331 [00:15<00:03, 13.06it/s]
 85%|████████▌ | 282/331 [00:15<00:03, 13.38it/s]
 86%|████████▌ | 284/331 [00:15<00:03, 13.47it/s]
 86%|████████▋ | 286/331 [00:16<00:03, 13.71it/s]
 87%|████████▋ | 288/331 [00:16<00:03, 13.57it/s]
 88%|████████▊ | 290/331 [00:16<00:02, 13.81it/s]
 88%|████████▊ | 292/331 [00:16<00:02, 13.85it/s]
 89%|████████▉ | 294/331 [00:16<00:02, 14.05it/s]
 89%|████████▉ | 296/331 [00:16<00:02, 13.74it/s]
 90%|█████████ | 298/331 [00:16<00:02, 13.72it/s]
 91%|█████████ | 300/331 [00:17<00:02, 13.67it/s]
 91%|█████████ | 302/331 [00:17<00:02, 13.58it/s]
 92%|█████████▏| 304/331 [00:17<00:02, 13.26it/s]
 92%|█████████▏| 306/331 [00:17<00:01, 13.24it/s]
 93%|█████████▎| 308/331 [00:17<00:01, 13.11it/s]
 94%|█████████▎| 310/331 [00:17<00:01, 13.16it/s]
 94%|█████████▍| 312/331 [00:18<00:01, 12.99it/s]
 95%|█████████▍| 314/331 [00:18<00:01, 13.05it/s]
 95%|█████████▌| 316/331 [00:18<00:01, 12.90it/s]
 96%|█████████▌| 318/331 [00:18<00:01, 12.78it/s]
 97%|█████████▋| 320/331 [00:18<00:00, 12.40it/s]
 97%|█████████▋| 322/331 [00:18<00:00, 11.87it/s]
 98%|█████████▊| 324/331 [00:19<00:00, 11.00it/s]
 98%|█████████▊| 326/331 [00:19<00:00, 10.34it/s]
 99%|█████████▉| 328/331 [00:19<00:00,  9.53it/s]
 99%|█████████▉| 329/331 [00:19<00:00,  9.27it/s]
100%|█████████▉| 330/331 [00:19<00:00,  9.00it/s]
100%|██████████| 331/331 [00:19<00:00,  8.71it/s]
100%|██████████| 331/331 [00:19<00:00, 16.59it/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 22.689 seconds)

Gallery generated by Sphinx-Gallery