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<01:15,  4.40it/s]
  2%|▏         | 5/331 [00:00<00:19, 16.66it/s]
  3%|▎         | 9/331 [00:00<00:13, 23.34it/s]
  4%|▍         | 13/331 [00:00<00:11, 27.80it/s]
  5%|▌         | 17/331 [00:00<00:10, 30.80it/s]
  6%|▋         | 21/331 [00:00<00:09, 32.03it/s]
  8%|▊         | 25/331 [00:00<00:09, 32.77it/s]
  9%|▉         | 29/331 [00:01<00:09, 32.74it/s]
 10%|▉         | 33/331 [00:01<00:09, 29.97it/s]
 11%|█         | 37/331 [00:01<00:11, 25.77it/s]
 12%|█▏        | 40/331 [00:01<00:12, 24.08it/s]
 13%|█▎        | 43/331 [00:01<00:12, 22.17it/s]
 14%|█▍        | 46/331 [00:01<00:13, 21.42it/s]
 15%|█▍        | 49/331 [00:02<00:13, 20.53it/s]
 16%|█▌        | 52/331 [00:02<00:13, 20.68it/s]
 17%|█▋        | 55/331 [00:02<00:13, 20.37it/s]
 18%|█▊        | 58/331 [00:02<00:13, 20.18it/s]
 18%|█▊        | 61/331 [00:02<00:13, 19.90it/s]
 19%|█▉        | 64/331 [00:02<00:13, 19.75it/s]
 20%|█▉        | 66/331 [00:02<00:13, 19.75it/s]
 21%|██        | 68/331 [00:02<00:13, 19.68it/s]
 21%|██        | 70/331 [00:03<00:13, 19.75it/s]
 22%|██▏       | 73/331 [00:03<00:12, 19.93it/s]
 23%|██▎       | 75/331 [00:03<00:13, 19.68it/s]
 23%|██▎       | 77/331 [00:03<00:12, 19.72it/s]
 24%|██▍       | 80/331 [00:03<00:12, 19.98it/s]
 25%|██▍       | 82/331 [00:03<00:12, 19.82it/s]
 26%|██▌       | 85/331 [00:03<00:12, 19.89it/s]
 27%|██▋       | 88/331 [00:03<00:12, 19.99it/s]
 27%|██▋       | 91/331 [00:04<00:11, 20.61it/s]
 28%|██▊       | 94/331 [00:04<00:10, 21.84it/s]
 29%|██▉       | 97/331 [00:04<00:10, 22.05it/s]
 30%|███       | 100/331 [00:04<00:10, 22.59it/s]
 31%|███       | 103/331 [00:04<00:09, 22.81it/s]
 32%|███▏      | 106/331 [00:04<00:09, 22.92it/s]
 33%|███▎      | 109/331 [00:04<00:09, 23.40it/s]
 34%|███▍      | 112/331 [00:05<00:09, 23.84it/s]
 35%|███▍      | 115/331 [00:05<00:08, 24.04it/s]
 36%|███▌      | 118/331 [00:05<00:08, 24.36it/s]
 37%|███▋      | 121/331 [00:05<00:08, 24.44it/s]
 37%|███▋      | 124/331 [00:05<00:08, 24.12it/s]
 38%|███▊      | 127/331 [00:05<00:08, 24.31it/s]
 39%|███▉      | 130/331 [00:05<00:08, 24.25it/s]
 40%|████      | 133/331 [00:05<00:08, 24.24it/s]
 41%|████      | 136/331 [00:05<00:08, 24.00it/s]
 42%|████▏     | 139/331 [00:06<00:08, 23.70it/s]
 43%|████▎     | 142/331 [00:06<00:08, 23.52it/s]
 44%|████▍     | 145/331 [00:06<00:07, 23.38it/s]
 45%|████▍     | 148/331 [00:06<00:07, 23.41it/s]
 46%|████▌     | 151/331 [00:06<00:07, 23.72it/s]
 47%|████▋     | 154/331 [00:06<00:07, 25.20it/s]
 48%|████▊     | 158/331 [00:06<00:06, 26.91it/s]
 49%|████▊     | 161/331 [00:06<00:06, 27.48it/s]
 50%|████▉     | 164/331 [00:07<00:05, 28.03it/s]
 50%|█████     | 167/331 [00:07<00:08, 19.74it/s]
 51%|█████▏    | 170/331 [00:07<00:11, 13.52it/s]
 52%|█████▏    | 172/331 [00:07<00:13, 11.96it/s]
 53%|█████▎    | 174/331 [00:08<00:14, 11.07it/s]
 53%|█████▎    | 176/331 [00:08<00:14, 10.66it/s]
 54%|█████▍    | 178/331 [00:08<00:14, 10.51it/s]
 54%|█████▍    | 180/331 [00:08<00:14, 10.53it/s]
 55%|█████▍    | 182/331 [00:08<00:13, 10.70it/s]
 56%|█████▌    | 184/331 [00:09<00:13, 10.94it/s]
 56%|█████▌    | 186/331 [00:09<00:12, 11.32it/s]
 57%|█████▋    | 188/331 [00:09<00:12, 11.54it/s]
 57%|█████▋    | 190/331 [00:09<00:11, 12.03it/s]
 58%|█████▊    | 192/331 [00:09<00:11, 12.41it/s]
 59%|█████▊    | 194/331 [00:09<00:10, 12.98it/s]
 59%|█████▉    | 196/331 [00:10<00:09, 13.55it/s]
 60%|█████▉    | 198/331 [00:10<00:09, 14.01it/s]
 60%|██████    | 200/331 [00:10<00:09, 14.35it/s]
 61%|██████    | 202/331 [00:10<00:08, 14.40it/s]
 62%|██████▏   | 204/331 [00:10<00:08, 14.49it/s]
 62%|██████▏   | 206/331 [00:10<00:08, 14.50it/s]
 63%|██████▎   | 208/331 [00:10<00:08, 14.47it/s]
 63%|██████▎   | 210/331 [00:10<00:08, 14.51it/s]
 64%|██████▍   | 212/331 [00:11<00:08, 14.65it/s]
 65%|██████▍   | 214/331 [00:11<00:08, 14.32it/s]
 65%|██████▌   | 216/331 [00:11<00:08, 13.97it/s]
 66%|██████▌   | 218/331 [00:11<00:08, 13.20it/s]
 66%|██████▋   | 220/331 [00:11<00:08, 13.08it/s]
 67%|██████▋   | 222/331 [00:11<00:08, 12.86it/s]
 68%|██████▊   | 224/331 [00:12<00:08, 13.04it/s]
 68%|██████▊   | 226/331 [00:12<00:08, 12.86it/s]
 69%|██████▉   | 228/331 [00:12<00:07, 13.22it/s]
 69%|██████▉   | 230/331 [00:12<00:07, 13.35it/s]
 70%|███████   | 232/331 [00:12<00:07, 13.60it/s]
 71%|███████   | 234/331 [00:12<00:07, 13.79it/s]
 71%|███████▏  | 236/331 [00:12<00:06, 13.77it/s]
 72%|███████▏  | 238/331 [00:13<00:06, 13.90it/s]
 73%|███████▎  | 240/331 [00:13<00:06, 14.06it/s]
 73%|███████▎  | 242/331 [00:13<00:06, 14.08it/s]
 74%|███████▎  | 244/331 [00:13<00:06, 14.13it/s]
 74%|███████▍  | 246/331 [00:13<00:06, 13.89it/s]
 75%|███████▍  | 248/331 [00:13<00:06, 13.79it/s]
 76%|███████▌  | 250/331 [00:13<00:05, 13.70it/s]
 76%|███████▌  | 252/331 [00:14<00:05, 13.78it/s]
 77%|███████▋  | 254/331 [00:14<00:05, 13.52it/s]
 77%|███████▋  | 256/331 [00:14<00:05, 13.46it/s]
 78%|███████▊  | 258/331 [00:14<00:05, 13.43it/s]
 79%|███████▊  | 260/331 [00:14<00:05, 13.58it/s]
 79%|███████▉  | 262/331 [00:14<00:05, 13.51it/s]
 80%|███████▉  | 264/331 [00:14<00:05, 13.30it/s]
 80%|████████  | 266/331 [00:15<00:04, 13.31it/s]
 81%|████████  | 268/331 [00:15<00:04, 13.42it/s]
 82%|████████▏ | 270/331 [00:15<00:04, 13.32it/s]
 82%|████████▏ | 272/331 [00:15<00:04, 13.38it/s]
 83%|████████▎ | 274/331 [00:15<00:04, 13.28it/s]
 83%|████████▎ | 276/331 [00:15<00:04, 13.28it/s]
 84%|████████▍ | 278/331 [00:16<00:04, 13.18it/s]
 85%|████████▍ | 280/331 [00:16<00:03, 13.29it/s]
 85%|████████▌ | 282/331 [00:16<00:03, 13.28it/s]
 86%|████████▌ | 284/331 [00:16<00:03, 13.38it/s]
 86%|████████▋ | 286/331 [00:16<00:03, 13.16it/s]
 87%|████████▋ | 288/331 [00:16<00:03, 13.34it/s]
 88%|████████▊ | 290/331 [00:16<00:03, 13.13it/s]
 88%|████████▊ | 292/331 [00:17<00:02, 13.35it/s]
 89%|████████▉ | 294/331 [00:17<00:02, 13.19it/s]
 89%|████████▉ | 296/331 [00:17<00:02, 13.36it/s]
 90%|█████████ | 298/331 [00:17<00:02, 13.40it/s]
 91%|█████████ | 300/331 [00:17<00:02, 13.48it/s]
 91%|█████████ | 302/331 [00:17<00:02, 13.27it/s]
 92%|█████████▏| 304/331 [00:17<00:02, 13.28it/s]
 92%|█████████▏| 306/331 [00:18<00:01, 13.04it/s]
 93%|█████████▎| 308/331 [00:18<00:01, 12.85it/s]
 94%|█████████▎| 310/331 [00:18<00:01, 12.54it/s]
 94%|█████████▍| 312/331 [00:18<00:01, 12.61it/s]
 95%|█████████▍| 314/331 [00:18<00:01, 12.31it/s]
 95%|█████████▌| 316/331 [00:18<00:01, 12.40it/s]
 96%|█████████▌| 318/331 [00:19<00:01, 11.91it/s]
 97%|█████████▋| 320/331 [00:19<00:00, 11.67it/s]
 97%|█████████▋| 322/331 [00:19<00:00, 11.11it/s]
 98%|█████████▊| 324/331 [00:19<00:00, 10.41it/s]
 98%|█████████▊| 326/331 [00:19<00:00,  9.72it/s]
 99%|█████████▉| 327/331 [00:20<00:00,  9.39it/s]
 99%|█████████▉| 328/331 [00:20<00:00,  8.91it/s]
 99%|█████████▉| 329/331 [00:20<00:00,  8.43it/s]
100%|█████████▉| 330/331 [00:20<00:00,  8.04it/s]
100%|██████████| 331/331 [00:20<00:00,  7.78it/s]
100%|██████████| 331/331 [00:20<00:00, 16.02it/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 23.553 seconds)

Gallery generated by Sphinx-Gallery