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 (1088, 660) to (1088, 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:56,  5.79it/s]
  2%|▏         | 6/331 [00:00<00:13, 23.57it/s]
  3%|▎         | 11/331 [00:00<00:09, 33.08it/s]
  5%|▌         | 17/331 [00:00<00:07, 40.14it/s]
  7%|▋         | 22/331 [00:00<00:07, 42.70it/s]
  8%|▊         | 27/331 [00:00<00:06, 44.09it/s]
 10%|▉         | 32/331 [00:00<00:07, 42.59it/s]
 11%|█         | 37/331 [00:01<00:08, 36.35it/s]
 12%|█▏        | 41/331 [00:01<00:08, 33.77it/s]
 14%|█▎        | 45/331 [00:01<00:09, 30.18it/s]
 15%|█▍        | 49/331 [00:01<00:09, 28.57it/s]
 16%|█▌        | 52/331 [00:01<00:09, 28.13it/s]
 17%|█▋        | 55/331 [00:01<00:09, 28.03it/s]
 18%|█▊        | 58/331 [00:01<00:09, 27.48it/s]
 18%|█▊        | 61/331 [00:01<00:09, 27.45it/s]
 19%|█▉        | 64/331 [00:02<00:09, 27.26it/s]
 20%|██        | 67/331 [00:02<00:09, 27.43it/s]
 21%|██        | 70/331 [00:02<00:09, 27.54it/s]
 22%|██▏       | 73/331 [00:02<00:09, 27.83it/s]
 23%|██▎       | 76/331 [00:02<00:09, 26.54it/s]
 24%|██▍       | 79/331 [00:02<00:09, 26.58it/s]
 25%|██▍       | 82/331 [00:02<00:09, 26.24it/s]
 26%|██▌       | 85/331 [00:02<00:09, 26.07it/s]
 27%|██▋       | 88/331 [00:02<00:09, 26.58it/s]
 27%|██▋       | 91/331 [00:03<00:08, 27.38it/s]
 28%|██▊       | 94/331 [00:03<00:08, 27.97it/s]
 30%|██▉       | 98/331 [00:03<00:07, 29.65it/s]
 31%|███       | 102/331 [00:03<00:07, 29.99it/s]
 32%|███▏      | 106/331 [00:03<00:07, 30.53it/s]
 33%|███▎      | 110/331 [00:03<00:07, 30.16it/s]
 34%|███▍      | 114/331 [00:03<00:07, 30.44it/s]
 36%|███▌      | 118/331 [00:03<00:06, 30.48it/s]
 37%|███▋      | 122/331 [00:04<00:07, 29.74it/s]
 38%|███▊      | 126/331 [00:04<00:06, 30.02it/s]
 39%|███▉      | 130/331 [00:04<00:06, 30.91it/s]
 40%|████      | 134/331 [00:04<00:06, 31.43it/s]
 42%|████▏     | 138/331 [00:04<00:06, 30.53it/s]
 43%|████▎     | 142/331 [00:04<00:06, 30.59it/s]
 44%|████▍     | 146/331 [00:04<00:06, 30.79it/s]
 45%|████▌     | 150/331 [00:04<00:05, 30.60it/s]
 47%|████▋     | 154/331 [00:05<00:05, 32.86it/s]
 48%|████▊     | 158/331 [00:05<00:05, 33.98it/s]
 49%|████▉     | 162/331 [00:05<00:04, 35.11it/s]
 50%|█████     | 167/331 [00:05<00:06, 27.10it/s]
 52%|█████▏    | 171/331 [00:05<00:08, 17.88it/s]
 53%|█████▎    | 174/331 [00:06<00:10, 15.69it/s]
 53%|█████▎    | 177/331 [00:06<00:10, 14.82it/s]
 54%|█████▍    | 179/331 [00:06<00:10, 14.70it/s]
 55%|█████▍    | 181/331 [00:06<00:10, 14.77it/s]
 55%|█████▌    | 183/331 [00:06<00:09, 15.01it/s]
 56%|█████▌    | 185/331 [00:06<00:09, 15.44it/s]
 56%|█████▋    | 187/331 [00:07<00:09, 15.70it/s]
 57%|█████▋    | 189/331 [00:07<00:08, 16.23it/s]
 58%|█████▊    | 191/331 [00:07<00:08, 16.98it/s]
 59%|█████▊    | 194/331 [00:07<00:07, 18.10it/s]
 60%|█████▉    | 197/331 [00:07<00:07, 19.01it/s]
 60%|██████    | 200/331 [00:07<00:06, 19.87it/s]
 61%|██████▏   | 203/331 [00:07<00:06, 19.91it/s]
 62%|██████▏   | 206/331 [00:08<00:06, 20.37it/s]
 63%|██████▎   | 209/331 [00:08<00:06, 20.05it/s]
 64%|██████▍   | 212/331 [00:08<00:05, 20.30it/s]
 65%|██████▍   | 215/331 [00:08<00:05, 19.42it/s]
 66%|██████▌   | 217/331 [00:08<00:06, 18.66it/s]
 66%|██████▌   | 219/331 [00:08<00:06, 17.90it/s]
 67%|██████▋   | 221/331 [00:08<00:06, 17.67it/s]
 67%|██████▋   | 223/331 [00:08<00:06, 17.54it/s]
 68%|██████▊   | 225/331 [00:09<00:06, 17.57it/s]
 69%|██████▊   | 227/331 [00:09<00:05, 17.66it/s]
 69%|██████▉   | 229/331 [00:09<00:05, 17.94it/s]
 70%|██████▉   | 231/331 [00:09<00:05, 18.19it/s]
 71%|███████   | 234/331 [00:09<00:05, 18.87it/s]
 71%|███████▏  | 236/331 [00:09<00:05, 18.54it/s]
 72%|███████▏  | 238/331 [00:09<00:05, 18.56it/s]
 73%|███████▎  | 240/331 [00:09<00:04, 18.67it/s]
 73%|███████▎  | 242/331 [00:10<00:04, 18.69it/s]
 74%|███████▎  | 244/331 [00:10<00:04, 18.69it/s]
 74%|███████▍  | 246/331 [00:10<00:04, 18.76it/s]
 75%|███████▍  | 248/331 [00:10<00:04, 18.61it/s]
 76%|███████▌  | 250/331 [00:10<00:04, 18.16it/s]
 76%|███████▌  | 252/331 [00:10<00:04, 17.91it/s]
 77%|███████▋  | 254/331 [00:10<00:04, 18.14it/s]
 77%|███████▋  | 256/331 [00:10<00:04, 17.98it/s]
 78%|███████▊  | 258/331 [00:10<00:04, 17.75it/s]
 79%|███████▊  | 260/331 [00:11<00:04, 17.72it/s]
 79%|███████▉  | 262/331 [00:11<00:03, 17.76it/s]
 80%|███████▉  | 264/331 [00:11<00:03, 17.47it/s]
 80%|████████  | 266/331 [00:11<00:03, 17.62it/s]
 81%|████████  | 268/331 [00:11<00:03, 17.20it/s]
 82%|████████▏ | 270/331 [00:11<00:03, 17.09it/s]
 82%|████████▏ | 272/331 [00:11<00:03, 16.94it/s]
 83%|████████▎ | 274/331 [00:11<00:03, 16.99it/s]
 83%|████████▎ | 276/331 [00:11<00:03, 16.91it/s]
 84%|████████▍ | 278/331 [00:12<00:03, 16.87it/s]
 85%|████████▍ | 280/331 [00:12<00:03, 16.84it/s]
 85%|████████▌ | 282/331 [00:12<00:02, 16.79it/s]
 86%|████████▌ | 284/331 [00:12<00:02, 17.04it/s]
 86%|████████▋ | 286/331 [00:12<00:02, 17.17it/s]
 87%|████████▋ | 288/331 [00:12<00:02, 17.18it/s]
 88%|████████▊ | 290/331 [00:12<00:02, 17.07it/s]
 88%|████████▊ | 292/331 [00:12<00:02, 17.13it/s]
 89%|████████▉ | 294/331 [00:13<00:02, 17.21it/s]
 89%|████████▉ | 296/331 [00:13<00:02, 17.18it/s]
 90%|█████████ | 298/331 [00:13<00:01, 17.33it/s]
 91%|█████████ | 300/331 [00:13<00:01, 17.34it/s]
 91%|█████████ | 302/331 [00:13<00:01, 17.42it/s]
 92%|█████████▏| 304/331 [00:13<00:01, 17.26it/s]
 92%|█████████▏| 306/331 [00:13<00:01, 17.29it/s]
 93%|█████████▎| 308/331 [00:13<00:01, 16.99it/s]
 94%|█████████▎| 310/331 [00:13<00:01, 16.94it/s]
 94%|█████████▍| 312/331 [00:14<00:01, 16.73it/s]
 95%|█████████▍| 314/331 [00:14<00:01, 16.54it/s]
 95%|█████████▌| 316/331 [00:14<00:00, 16.32it/s]
 96%|█████████▌| 318/331 [00:14<00:00, 15.73it/s]
 97%|█████████▋| 320/331 [00:14<00:00, 15.14it/s]
 97%|█████████▋| 322/331 [00:14<00:00, 14.45it/s]
 98%|█████████▊| 324/331 [00:14<00:00, 13.26it/s]
 98%|█████████▊| 326/331 [00:15<00:00, 12.45it/s]
 99%|█████████▉| 328/331 [00:15<00:00, 11.56it/s]
100%|█████████▉| 330/331 [00:15<00:00, 10.90it/s]
100%|██████████| 331/331 [00:15<00:00, 21.18it/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.167 seconds)

Gallery generated by Sphinx-Gallery