Note
Go to the end to download the full example code.
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 (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<04:13, 1.30it/s]
1%| | 4/331 [00:00<00:58, 5.63it/s]
2%|▏ | 7/331 [00:00<00:32, 9.96it/s]
3%|▎ | 11/331 [00:01<00:21, 15.09it/s]
5%|▍ | 15/331 [00:01<00:16, 18.73it/s]
5%|▌ | 18/331 [00:01<00:14, 21.09it/s]
6%|▋ | 21/331 [00:01<00:13, 22.66it/s]
7%|▋ | 24/331 [00:01<00:12, 23.71it/s]
8%|▊ | 27/331 [00:01<00:12, 24.21it/s]
9%|▉ | 30/331 [00:01<00:12, 24.42it/s]
10%|▉ | 33/331 [00:01<00:12, 23.39it/s]
11%|█ | 36/331 [00:02<00:13, 21.08it/s]
12%|█▏ | 39/331 [00:02<00:14, 20.30it/s]
13%|█▎ | 42/331 [00:02<00:15, 19.06it/s]
13%|█▎ | 44/331 [00:02<00:16, 17.09it/s]
14%|█▍ | 46/331 [00:02<00:17, 16.62it/s]
15%|█▍ | 48/331 [00:02<00:17, 16.05it/s]
15%|█▌ | 50/331 [00:03<00:17, 15.85it/s]
16%|█▌ | 52/331 [00:03<00:17, 15.83it/s]
16%|█▋ | 54/331 [00:03<00:18, 15.19it/s]
17%|█▋ | 56/331 [00:03<00:18, 15.22it/s]
18%|█▊ | 58/331 [00:03<00:18, 15.08it/s]
18%|█▊ | 60/331 [00:03<00:17, 15.19it/s]
19%|█▊ | 62/331 [00:03<00:17, 15.04it/s]
19%|█▉ | 64/331 [00:03<00:17, 15.10it/s]
20%|█▉ | 66/331 [00:04<00:17, 15.19it/s]
21%|██ | 68/331 [00:04<00:17, 15.21it/s]
21%|██ | 70/331 [00:04<00:17, 15.23it/s]
22%|██▏ | 72/331 [00:04<00:17, 15.21it/s]
22%|██▏ | 74/331 [00:04<00:16, 15.34it/s]
23%|██▎ | 76/331 [00:04<00:16, 15.15it/s]
24%|██▎ | 78/331 [00:04<00:17, 14.82it/s]
24%|██▍ | 80/331 [00:05<00:16, 15.05it/s]
25%|██▍ | 82/331 [00:05<00:15, 16.00it/s]
25%|██▌ | 84/331 [00:05<00:15, 16.39it/s]
26%|██▌ | 86/331 [00:05<00:14, 17.04it/s]
27%|██▋ | 88/331 [00:05<00:14, 17.08it/s]
27%|██▋ | 90/331 [00:05<00:13, 17.57it/s]
28%|██▊ | 92/331 [00:05<00:13, 17.69it/s]
28%|██▊ | 94/331 [00:05<00:13, 18.08it/s]
29%|██▉ | 96/331 [00:05<00:13, 17.88it/s]
30%|██▉ | 98/331 [00:06<00:12, 18.05it/s]
30%|███ | 100/331 [00:06<00:13, 17.64it/s]
31%|███ | 102/331 [00:06<00:12, 17.98it/s]
31%|███▏ | 104/331 [00:06<00:13, 17.25it/s]
32%|███▏ | 106/331 [00:06<00:12, 17.64it/s]
33%|███▎ | 108/331 [00:06<00:12, 17.54it/s]
33%|███▎ | 110/331 [00:06<00:12, 17.78it/s]
34%|███▍ | 112/331 [00:06<00:12, 17.62it/s]
34%|███▍ | 114/331 [00:06<00:12, 17.96it/s]
35%|███▌ | 116/331 [00:07<00:12, 17.65it/s]
36%|███▌ | 118/331 [00:07<00:11, 17.83it/s]
36%|███▋ | 120/331 [00:07<00:12, 17.17it/s]
37%|███▋ | 122/331 [00:07<00:11, 17.52it/s]
38%|███▊ | 125/331 [00:07<00:11, 18.45it/s]
38%|███▊ | 127/331 [00:07<00:11, 18.48it/s]
39%|███▉ | 129/331 [00:07<00:11, 17.80it/s]
40%|███▉ | 131/331 [00:07<00:11, 18.06it/s]
40%|████ | 133/331 [00:08<00:11, 17.53it/s]
41%|████ | 135/331 [00:08<00:12, 16.23it/s]
41%|████▏ | 137/331 [00:08<00:12, 16.05it/s]
42%|████▏ | 139/331 [00:08<00:12, 15.98it/s]
43%|████▎ | 141/331 [00:08<00:11, 16.19it/s]
43%|████▎ | 143/331 [00:08<00:11, 16.62it/s]
44%|████▍ | 145/331 [00:08<00:10, 16.92it/s]
44%|████▍ | 147/331 [00:08<00:10, 16.90it/s]
45%|████▌ | 149/331 [00:08<00:10, 17.25it/s]
46%|████▌ | 151/331 [00:09<00:10, 17.33it/s]
47%|████▋ | 154/331 [00:09<00:09, 18.94it/s]
47%|████▋ | 157/331 [00:09<00:08, 19.87it/s]
48%|████▊ | 160/331 [00:09<00:08, 20.52it/s]
49%|████▉ | 163/331 [00:09<00:07, 21.49it/s]
50%|█████ | 166/331 [00:09<00:07, 21.58it/s]
51%|█████ | 169/331 [00:10<00:22, 7.28it/s]
52%|█████▏ | 171/331 [00:11<00:28, 5.65it/s]
52%|█████▏ | 173/331 [00:12<00:33, 4.72it/s]
53%|█████▎ | 174/331 [00:12<00:35, 4.41it/s]
53%|█████▎ | 175/331 [00:12<00:37, 4.15it/s]
53%|█████▎ | 176/331 [00:12<00:39, 3.93it/s]
53%|█████▎ | 177/331 [00:13<00:41, 3.72it/s]
54%|█████▍ | 178/331 [00:13<00:42, 3.59it/s]
54%|█████▍ | 179/331 [00:13<00:43, 3.52it/s]
54%|█████▍ | 180/331 [00:14<00:43, 3.47it/s]
55%|█████▍ | 181/331 [00:14<00:43, 3.42it/s]
55%|█████▍ | 182/331 [00:14<00:43, 3.46it/s]
55%|█████▌ | 183/331 [00:15<00:42, 3.49it/s]
56%|█████▌ | 184/331 [00:15<00:41, 3.51it/s]
56%|█████▌ | 185/331 [00:15<00:40, 3.59it/s]
56%|█████▌ | 186/331 [00:15<00:38, 3.73it/s]
56%|█████▋ | 187/331 [00:16<00:36, 3.90it/s]
57%|█████▋ | 188/331 [00:16<00:34, 4.13it/s]
57%|█████▋ | 189/331 [00:16<00:33, 4.23it/s]
57%|█████▋ | 190/331 [00:16<00:32, 4.39it/s]
58%|█████▊ | 191/331 [00:16<00:30, 4.65it/s]
58%|█████▊ | 192/331 [00:17<00:28, 4.90it/s]
58%|█████▊ | 193/331 [00:17<00:27, 5.11it/s]
59%|█████▊ | 194/331 [00:17<00:25, 5.39it/s]
59%|█████▉ | 195/331 [00:17<00:24, 5.56it/s]
59%|█████▉ | 196/331 [00:17<00:24, 5.60it/s]
60%|█████▉ | 197/331 [00:17<00:22, 5.84it/s]
60%|█████▉ | 198/331 [00:18<00:21, 6.11it/s]
60%|██████ | 199/331 [00:18<00:21, 6.28it/s]
60%|██████ | 200/331 [00:18<00:20, 6.26it/s]
61%|██████ | 201/331 [00:18<00:20, 6.26it/s]
61%|██████ | 202/331 [00:18<00:20, 6.21it/s]
61%|██████▏ | 203/331 [00:18<00:20, 6.20it/s]
62%|██████▏ | 204/331 [00:19<00:20, 6.16it/s]
62%|██████▏ | 205/331 [00:19<00:20, 6.19it/s]
62%|██████▏ | 206/331 [00:19<00:20, 5.96it/s]
63%|██████▎ | 207/331 [00:19<00:20, 6.04it/s]
63%|██████▎ | 208/331 [00:19<00:20, 5.99it/s]
63%|██████▎ | 209/331 [00:19<00:20, 5.87it/s]
63%|██████▎ | 210/331 [00:20<00:20, 5.86it/s]
64%|██████▎ | 211/331 [00:20<00:20, 5.96it/s]
64%|██████▍ | 212/331 [00:20<00:19, 6.03it/s]
64%|██████▍ | 213/331 [00:20<00:19, 6.01it/s]
65%|██████▍ | 214/331 [00:20<00:19, 6.00it/s]
65%|██████▍ | 215/331 [00:20<00:19, 6.02it/s]
65%|██████▌ | 216/331 [00:21<00:19, 6.03it/s]
66%|██████▌ | 217/331 [00:21<00:18, 6.01it/s]
66%|██████▌ | 218/331 [00:21<00:18, 5.95it/s]
66%|██████▌ | 219/331 [00:21<00:18, 6.04it/s]
66%|██████▋ | 220/331 [00:21<00:18, 6.07it/s]
67%|██████▋ | 221/331 [00:21<00:18, 5.98it/s]
67%|██████▋ | 222/331 [00:22<00:18, 6.05it/s]
67%|██████▋ | 223/331 [00:22<00:18, 5.99it/s]
68%|██████▊ | 224/331 [00:22<00:18, 5.94it/s]
68%|██████▊ | 225/331 [00:22<00:17, 5.94it/s]
68%|██████▊ | 226/331 [00:22<00:17, 5.94it/s]
69%|██████▊ | 227/331 [00:22<00:17, 5.84it/s]
69%|██████▉ | 228/331 [00:23<00:17, 5.78it/s]
69%|██████▉ | 229/331 [00:23<00:17, 5.82it/s]
69%|██████▉ | 230/331 [00:23<00:17, 5.84it/s]
70%|██████▉ | 231/331 [00:23<00:17, 5.85it/s]
70%|███████ | 232/331 [00:23<00:16, 5.86it/s]
70%|███████ | 233/331 [00:23<00:16, 5.83it/s]
71%|███████ | 234/331 [00:24<00:16, 5.74it/s]
71%|███████ | 235/331 [00:24<00:16, 5.77it/s]
71%|███████▏ | 236/331 [00:24<00:16, 5.76it/s]
72%|███████▏ | 237/331 [00:24<00:16, 5.63it/s]
72%|███████▏ | 238/331 [00:24<00:16, 5.68it/s]
72%|███████▏ | 239/331 [00:24<00:16, 5.64it/s]
73%|███████▎ | 240/331 [00:25<00:16, 5.54it/s]
73%|███████▎ | 241/331 [00:25<00:16, 5.59it/s]
73%|███████▎ | 242/331 [00:25<00:15, 5.58it/s]
73%|███████▎ | 243/331 [00:25<00:15, 5.54it/s]
74%|███████▎ | 244/331 [00:25<00:15, 5.47it/s]
74%|███████▍ | 245/331 [00:26<00:15, 5.61it/s]
74%|███████▍ | 246/331 [00:26<00:14, 5.75it/s]
75%|███████▍ | 247/331 [00:26<00:14, 5.76it/s]
75%|███████▍ | 248/331 [00:26<00:14, 5.72it/s]
75%|███████▌ | 249/331 [00:26<00:14, 5.59it/s]
76%|███████▌ | 250/331 [00:26<00:14, 5.59it/s]
76%|███████▌ | 251/331 [00:27<00:14, 5.65it/s]
76%|███████▌ | 252/331 [00:27<00:13, 5.67it/s]
76%|███████▋ | 253/331 [00:27<00:13, 5.62it/s]
77%|███████▋ | 254/331 [00:27<00:13, 5.68it/s]
77%|███████▋ | 255/331 [00:27<00:13, 5.74it/s]
77%|███████▋ | 256/331 [00:27<00:13, 5.56it/s]
78%|███████▊ | 257/331 [00:28<00:13, 5.68it/s]
78%|███████▊ | 258/331 [00:28<00:12, 5.77it/s]
78%|███████▊ | 259/331 [00:28<00:12, 5.80it/s]
79%|███████▊ | 260/331 [00:28<00:12, 5.84it/s]
79%|███████▉ | 261/331 [00:28<00:11, 5.89it/s]
79%|███████▉ | 262/331 [00:29<00:12, 5.66it/s]
79%|███████▉ | 263/331 [00:29<00:11, 5.67it/s]
80%|███████▉ | 264/331 [00:29<00:11, 5.59it/s]
80%|████████ | 265/331 [00:29<00:11, 5.58it/s]
80%|████████ | 266/331 [00:29<00:11, 5.55it/s]
81%|████████ | 267/331 [00:29<00:11, 5.54it/s]
81%|████████ | 268/331 [00:30<00:11, 5.46it/s]
81%|████████▏ | 269/331 [00:30<00:11, 5.49it/s]
82%|████████▏ | 270/331 [00:30<00:11, 5.52it/s]
82%|████████▏ | 271/331 [00:30<00:10, 5.53it/s]
82%|████████▏ | 272/331 [00:30<00:10, 5.39it/s]
82%|████████▏ | 273/331 [00:31<00:10, 5.32it/s]
83%|████████▎ | 274/331 [00:31<00:10, 5.56it/s]
83%|████████▎ | 275/331 [00:31<00:09, 5.75it/s]
83%|████████▎ | 276/331 [00:31<00:09, 5.82it/s]
84%|████████▎ | 277/331 [00:31<00:09, 5.64it/s]
84%|████████▍ | 278/331 [00:31<00:09, 5.77it/s]
84%|████████▍ | 279/331 [00:32<00:08, 5.95it/s]
85%|████████▍ | 280/331 [00:32<00:08, 5.93it/s]
85%|████████▍ | 281/331 [00:32<00:08, 5.99it/s]
85%|████████▌ | 282/331 [00:32<00:08, 5.86it/s]
85%|████████▌ | 283/331 [00:32<00:08, 5.82it/s]
86%|████████▌ | 284/331 [00:32<00:08, 5.71it/s]
86%|████████▌ | 285/331 [00:33<00:07, 5.76it/s]
86%|████████▋ | 286/331 [00:33<00:07, 5.77it/s]
87%|████████▋ | 287/331 [00:33<00:07, 5.80it/s]
87%|████████▋ | 288/331 [00:33<00:07, 5.80it/s]
87%|████████▋ | 289/331 [00:33<00:07, 5.70it/s]
88%|████████▊ | 290/331 [00:33<00:07, 5.84it/s]
88%|████████▊ | 291/331 [00:34<00:06, 5.89it/s]
88%|████████▊ | 292/331 [00:34<00:06, 5.93it/s]
89%|████████▊ | 293/331 [00:34<00:06, 6.06it/s]
89%|████████▉ | 294/331 [00:34<00:06, 6.16it/s]
89%|████████▉ | 295/331 [00:34<00:05, 6.21it/s]
89%|████████▉ | 296/331 [00:34<00:05, 6.05it/s]
90%|████████▉ | 297/331 [00:35<00:05, 5.99it/s]
90%|█████████ | 298/331 [00:35<00:05, 5.95it/s]
90%|█████████ | 299/331 [00:35<00:05, 6.04it/s]
91%|█████████ | 300/331 [00:35<00:05, 6.07it/s]
91%|█████████ | 301/331 [00:35<00:04, 6.17it/s]
91%|█████████ | 302/331 [00:35<00:04, 5.85it/s]
92%|█████████▏| 303/331 [00:36<00:04, 5.80it/s]
92%|█████████▏| 304/331 [00:36<00:04, 5.70it/s]
92%|█████████▏| 305/331 [00:36<00:04, 5.78it/s]
92%|█████████▏| 306/331 [00:36<00:04, 5.78it/s]
93%|█████████▎| 307/331 [00:36<00:04, 5.67it/s]
93%|█████████▎| 308/331 [00:37<00:04, 5.53it/s]
93%|█████████▎| 309/331 [00:37<00:03, 5.63it/s]
94%|█████████▎| 310/331 [00:37<00:03, 5.68it/s]
94%|█████████▍| 311/331 [00:37<00:03, 5.74it/s]
94%|█████████▍| 312/331 [00:37<00:03, 5.72it/s]
95%|█████████▍| 313/331 [00:37<00:03, 5.75it/s]
95%|█████████▍| 314/331 [00:38<00:02, 5.75it/s]
95%|█████████▌| 315/331 [00:38<00:02, 5.74it/s]
95%|█████████▌| 316/331 [00:38<00:02, 5.61it/s]
96%|█████████▌| 317/331 [00:38<00:02, 5.58it/s]
96%|█████████▌| 318/331 [00:38<00:02, 5.47it/s]
96%|█████████▋| 319/331 [00:38<00:02, 5.37it/s]
97%|█████████▋| 320/331 [00:39<00:02, 5.05it/s]
97%|█████████▋| 321/331 [00:39<00:02, 4.90it/s]
97%|█████████▋| 322/331 [00:39<00:01, 4.78it/s]
98%|█████████▊| 323/331 [00:39<00:01, 4.56it/s]
98%|█████████▊| 324/331 [00:40<00:01, 4.32it/s]
98%|█████████▊| 325/331 [00:40<00:01, 4.18it/s]
98%|█████████▊| 326/331 [00:40<00:01, 3.99it/s]
99%|█████████▉| 327/331 [00:40<00:01, 3.82it/s]
99%|█████████▉| 328/331 [00:41<00:00, 3.64it/s]
99%|█████████▉| 329/331 [00:41<00:00, 3.55it/s]
100%|█████████▉| 330/331 [00:41<00:00, 3.51it/s]
100%|██████████| 331/331 [00:42<00:00, 3.40it/s]
100%|██████████| 331/331 [00:42<00:00, 7.85it/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 45.586 seconds)