Note
Go to the end to download the full example code.
Animate 2D#
Display a labels layer above of an image layer using the add_labels and add_image APIs
Rendering frames...
0%| | 0/166 [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).
1%| | 1/166 [00:00<00:35, 4.70it/s]
2%|▏ | 4/166 [00:00<00:11, 13.64it/s]
5%|▍ | 8/166 [00:00<00:07, 20.46it/s]
7%|▋ | 11/166 [00:00<00:06, 22.80it/s]
9%|▉ | 15/166 [00:00<00:05, 25.57it/s]
11%|█ | 18/166 [00:00<00:05, 26.75it/s]
13%|█▎ | 21/166 [00:00<00:05, 26.98it/s]
14%|█▍ | 24/166 [00:01<00:05, 27.00it/s]
16%|█▋ | 27/166 [00:01<00:05, 26.72it/s]
18%|█▊ | 30/166 [00:01<00:05, 26.23it/s]
20%|█▉ | 33/166 [00:01<00:05, 23.24it/s]
22%|██▏ | 36/166 [00:01<00:06, 20.05it/s]
23%|██▎ | 39/166 [00:01<00:06, 18.56it/s]
25%|██▍ | 41/166 [00:01<00:06, 17.86it/s]
26%|██▌ | 43/166 [00:02<00:07, 16.12it/s]
27%|██▋ | 45/166 [00:02<00:07, 16.74it/s]
28%|██▊ | 47/166 [00:02<00:07, 15.92it/s]
30%|██▉ | 49/166 [00:02<00:07, 16.12it/s]
31%|███ | 51/166 [00:02<00:06, 16.81it/s]
32%|███▏ | 53/166 [00:02<00:06, 16.40it/s]
33%|███▎ | 55/166 [00:02<00:07, 15.72it/s]
34%|███▍ | 57/166 [00:02<00:07, 15.51it/s]
36%|███▌ | 59/166 [00:03<00:07, 15.17it/s]
37%|███▋ | 61/166 [00:03<00:06, 15.22it/s]
38%|███▊ | 63/166 [00:03<00:06, 15.05it/s]
39%|███▉ | 65/166 [00:03<00:06, 15.20it/s]
40%|████ | 67/166 [00:03<00:06, 15.12it/s]
42%|████▏ | 69/166 [00:03<00:06, 15.76it/s]
43%|████▎ | 71/166 [00:03<00:05, 16.39it/s]
44%|████▍ | 73/166 [00:03<00:05, 16.83it/s]
45%|████▌ | 75/166 [00:04<00:05, 17.09it/s]
46%|████▋ | 77/166 [00:04<00:05, 17.00it/s]
48%|████▊ | 79/166 [00:04<00:04, 17.41it/s]
49%|████▉ | 81/166 [00:04<00:04, 17.31it/s]
50%|█████ | 83/166 [00:04<00:04, 17.82it/s]
51%|█████ | 85/166 [00:04<00:04, 17.45it/s]
52%|█████▏ | 87/166 [00:04<00:04, 16.82it/s]
54%|█████▎ | 89/166 [00:04<00:04, 16.47it/s]
55%|█████▍ | 91/166 [00:05<00:04, 16.10it/s]
56%|█████▌ | 93/166 [00:05<00:04, 16.39it/s]
57%|█████▋ | 95/166 [00:05<00:04, 16.95it/s]
58%|█████▊ | 97/166 [00:05<00:04, 16.90it/s]
60%|█████▉ | 99/166 [00:05<00:03, 17.12it/s]
61%|██████ | 101/166 [00:05<00:03, 17.12it/s]
62%|██████▏ | 103/166 [00:05<00:03, 17.54it/s]
63%|██████▎ | 105/166 [00:05<00:03, 17.30it/s]
64%|██████▍ | 107/166 [00:05<00:03, 17.67it/s]
66%|██████▌ | 109/166 [00:06<00:03, 17.69it/s]
67%|██████▋ | 111/166 [00:06<00:03, 17.94it/s]
68%|██████▊ | 113/166 [00:06<00:02, 17.72it/s]
69%|██████▉ | 115/166 [00:06<00:02, 18.12it/s]
70%|███████ | 117/166 [00:06<00:02, 17.92it/s]
72%|███████▏ | 119/166 [00:06<00:02, 18.25it/s]
73%|███████▎ | 121/166 [00:06<00:02, 17.48it/s]
75%|███████▍ | 124/166 [00:06<00:02, 18.84it/s]
76%|███████▌ | 126/166 [00:07<00:02, 17.40it/s]
77%|███████▋ | 128/166 [00:07<00:02, 17.66it/s]
78%|███████▊ | 130/166 [00:07<00:02, 16.77it/s]
80%|███████▉ | 132/166 [00:07<00:01, 17.33it/s]
81%|████████ | 134/166 [00:07<00:01, 17.59it/s]
82%|████████▏ | 136/166 [00:07<00:01, 18.07it/s]
83%|████████▎ | 138/166 [00:07<00:01, 17.68it/s]
84%|████████▍ | 140/166 [00:07<00:01, 17.80it/s]
86%|████████▌ | 142/166 [00:07<00:01, 18.26it/s]
87%|████████▋ | 144/166 [00:08<00:01, 18.32it/s]
88%|████████▊ | 146/166 [00:08<00:01, 18.58it/s]
89%|████████▉ | 148/166 [00:08<00:00, 18.34it/s]
90%|█████████ | 150/166 [00:08<00:00, 18.58it/s]
92%|█████████▏| 152/166 [00:08<00:00, 18.77it/s]
93%|█████████▎| 155/166 [00:08<00:00, 20.04it/s]
95%|█████████▌| 158/166 [00:08<00:00, 20.35it/s]
97%|█████████▋| 161/166 [00:08<00:00, 21.08it/s]
99%|█████████▉| 164/166 [00:08<00:00, 21.53it/s]
100%|██████████| 166/166 [00:09<00:00, 18.29it/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()
animation.animate("animate2D.mp4", canvas_only=False)
Total running time of the script: (0 minutes 14.617 seconds)