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, 636) 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<01:24, 3.88it/s]
2%|▏ | 5/331 [00:00<00:20, 15.53it/s]
3%|▎ | 9/331 [00:00<00:14, 22.97it/s]
4%|▍ | 13/331 [00:00<00:11, 27.92it/s]
5%|▌ | 17/331 [00:00<00:10, 31.35it/s]
6%|▋ | 21/331 [00:00<00:09, 32.55it/s]
8%|▊ | 25/331 [00:00<00:09, 33.29it/s]
9%|▉ | 29/331 [00:01<00:09, 33.04it/s]
10%|▉ | 33/331 [00:01<00:09, 30.35it/s]
11%|█ | 37/331 [00:01<00:10, 26.80it/s]
12%|█▏ | 40/331 [00:01<00:11, 25.12it/s]
13%|█▎ | 43/331 [00:01<00:12, 22.34it/s]
14%|█▍ | 46/331 [00:01<00:12, 22.09it/s]
15%|█▍ | 49/331 [00:01<00:13, 21.50it/s]
16%|█▌ | 52/331 [00:02<00:12, 21.88it/s]
17%|█▋ | 55/331 [00:02<00:12, 21.86it/s]
18%|█▊ | 58/331 [00:02<00:12, 21.86it/s]
18%|█▊ | 61/331 [00:02<00:12, 21.83it/s]
19%|█▉ | 64/331 [00:02<00:12, 21.81it/s]
20%|██ | 67/331 [00:02<00:12, 21.86it/s]
21%|██ | 70/331 [00:02<00:12, 21.69it/s]
22%|██▏ | 73/331 [00:03<00:12, 21.48it/s]
23%|██▎ | 76/331 [00:03<00:11, 21.51it/s]
24%|██▍ | 79/331 [00:03<00:11, 21.36it/s]
25%|██▍ | 82/331 [00:03<00:11, 21.47it/s]
26%|██▌ | 85/331 [00:03<00:11, 21.46it/s]
27%|██▋ | 88/331 [00:03<00:11, 21.48it/s]
27%|██▋ | 91/331 [00:03<00:10, 21.82it/s]
28%|██▊ | 94/331 [00:04<00:10, 23.05it/s]
29%|██▉ | 97/331 [00:04<00:09, 24.16it/s]
30%|███ | 100/331 [00:04<00:09, 24.97it/s]
31%|███ | 103/331 [00:04<00:08, 25.67it/s]
32%|███▏ | 106/331 [00:04<00:08, 25.91it/s]
33%|███▎ | 109/331 [00:04<00:08, 26.08it/s]
34%|███▍ | 112/331 [00:04<00:08, 26.39it/s]
35%|███▍ | 115/331 [00:04<00:08, 26.32it/s]
36%|███▌ | 118/331 [00:04<00:08, 26.53it/s]
37%|███▋ | 121/331 [00:05<00:07, 26.66it/s]
37%|███▋ | 124/331 [00:05<00:07, 26.22it/s]
38%|███▊ | 127/331 [00:05<00:07, 26.12it/s]
39%|███▉ | 130/331 [00:05<00:07, 26.42it/s]
40%|████ | 133/331 [00:05<00:07, 26.67it/s]
41%|████ | 136/331 [00:05<00:07, 26.98it/s]
42%|████▏ | 139/331 [00:05<00:07, 27.28it/s]
43%|████▎ | 142/331 [00:05<00:06, 27.37it/s]
44%|████▍ | 145/331 [00:05<00:06, 27.42it/s]
45%|████▍ | 148/331 [00:06<00:06, 27.04it/s]
46%|████▌ | 151/331 [00:06<00:06, 26.97it/s]
47%|████▋ | 155/331 [00:06<00:06, 28.18it/s]
48%|████▊ | 159/331 [00:06<00:05, 29.57it/s]
49%|████▉ | 163/331 [00:06<00:05, 30.56it/s]
50%|█████ | 167/331 [00:06<00:09, 17.04it/s]
51%|█████▏ | 170/331 [00:07<00:18, 8.76it/s]
52%|█████▏ | 172/331 [00:08<00:23, 6.88it/s]
53%|█████▎ | 174/331 [00:08<00:27, 5.75it/s]
53%|█████▎ | 176/331 [00:09<00:30, 5.06it/s]
53%|█████▎ | 177/331 [00:09<00:32, 4.79it/s]
54%|█████▍ | 178/331 [00:10<00:33, 4.53it/s]
54%|█████▍ | 179/331 [00:10<00:35, 4.32it/s]
54%|█████▍ | 180/331 [00:10<00:36, 4.16it/s]
55%|█████▍ | 181/331 [00:10<00:37, 4.02it/s]
55%|█████▍ | 182/331 [00:11<00:37, 3.98it/s]
55%|█████▌ | 183/331 [00:11<00:36, 4.02it/s]
56%|█████▌ | 184/331 [00:11<00:35, 4.09it/s]
56%|█████▌ | 185/331 [00:11<00:34, 4.21it/s]
56%|█████▌ | 186/331 [00:12<00:33, 4.35it/s]
56%|█████▋ | 187/331 [00:12<00:31, 4.56it/s]
57%|█████▋ | 188/331 [00:12<00:29, 4.79it/s]
57%|█████▋ | 189/331 [00:12<00:28, 5.00it/s]
57%|█████▋ | 190/331 [00:12<00:26, 5.26it/s]
58%|█████▊ | 191/331 [00:12<00:25, 5.54it/s]
58%|█████▊ | 192/331 [00:13<00:23, 5.85it/s]
58%|█████▊ | 193/331 [00:13<00:22, 6.15it/s]
59%|█████▊ | 194/331 [00:13<00:21, 6.45it/s]
59%|█████▉ | 195/331 [00:13<00:20, 6.75it/s]
59%|█████▉ | 196/331 [00:13<00:18, 7.19it/s]
60%|█████▉ | 197/331 [00:13<00:17, 7.49it/s]
60%|█████▉ | 198/331 [00:13<00:17, 7.65it/s]
60%|██████ | 199/331 [00:13<00:17, 7.76it/s]
60%|██████ | 200/331 [00:14<00:16, 7.85it/s]
61%|██████ | 201/331 [00:14<00:16, 7.95it/s]
61%|██████ | 202/331 [00:14<00:16, 8.01it/s]
61%|██████▏ | 203/331 [00:14<00:15, 8.04it/s]
62%|██████▏ | 204/331 [00:14<00:15, 8.03it/s]
62%|██████▏ | 205/331 [00:14<00:15, 8.06it/s]
62%|██████▏ | 206/331 [00:14<00:15, 8.05it/s]
63%|██████▎ | 207/331 [00:14<00:15, 8.05it/s]
63%|██████▎ | 208/331 [00:15<00:15, 8.05it/s]
63%|██████▎ | 209/331 [00:15<00:15, 8.00it/s]
63%|██████▎ | 210/331 [00:15<00:15, 7.92it/s]
64%|██████▎ | 211/331 [00:15<00:15, 7.94it/s]
64%|██████▍ | 212/331 [00:15<00:14, 7.97it/s]
64%|██████▍ | 213/331 [00:15<00:14, 7.87it/s]
65%|██████▍ | 214/331 [00:15<00:15, 7.74it/s]
65%|██████▍ | 215/331 [00:15<00:14, 7.82it/s]
65%|██████▌ | 216/331 [00:16<00:14, 7.78it/s]
66%|██████▌ | 217/331 [00:16<00:14, 7.74it/s]
66%|██████▌ | 218/331 [00:16<00:14, 7.78it/s]
66%|██████▌ | 219/331 [00:16<00:14, 7.79it/s]
66%|██████▋ | 220/331 [00:16<00:14, 7.83it/s]
67%|██████▋ | 221/331 [00:16<00:14, 7.76it/s]
67%|██████▋ | 222/331 [00:16<00:14, 7.65it/s]
67%|██████▋ | 223/331 [00:17<00:14, 7.36it/s]
68%|██████▊ | 224/331 [00:17<00:14, 7.48it/s]
68%|██████▊ | 225/331 [00:17<00:14, 7.54it/s]
68%|██████▊ | 226/331 [00:17<00:14, 7.49it/s]
69%|██████▊ | 227/331 [00:17<00:13, 7.58it/s]
69%|██████▉ | 228/331 [00:17<00:13, 7.59it/s]
69%|██████▉ | 229/331 [00:17<00:13, 7.59it/s]
69%|██████▉ | 230/331 [00:17<00:13, 7.60it/s]
70%|██████▉ | 231/331 [00:18<00:13, 7.56it/s]
70%|███████ | 232/331 [00:18<00:13, 7.47it/s]
70%|███████ | 233/331 [00:18<00:13, 7.39it/s]
71%|███████ | 234/331 [00:18<00:13, 7.46it/s]
71%|███████ | 235/331 [00:18<00:12, 7.45it/s]
71%|███████▏ | 236/331 [00:18<00:12, 7.51it/s]
72%|███████▏ | 237/331 [00:18<00:12, 7.41it/s]
72%|███████▏ | 238/331 [00:18<00:12, 7.45it/s]
72%|███████▏ | 239/331 [00:19<00:12, 7.50it/s]
73%|███████▎ | 240/331 [00:19<00:12, 7.51it/s]
73%|███████▎ | 241/331 [00:19<00:12, 7.46it/s]
73%|███████▎ | 242/331 [00:19<00:11, 7.46it/s]
73%|███████▎ | 243/331 [00:19<00:11, 7.50it/s]
74%|███████▎ | 244/331 [00:19<00:11, 7.52it/s]
74%|███████▍ | 245/331 [00:19<00:11, 7.40it/s]
74%|███████▍ | 246/331 [00:20<00:11, 7.41it/s]
75%|███████▍ | 247/331 [00:20<00:11, 7.42it/s]
75%|███████▍ | 248/331 [00:20<00:11, 7.43it/s]
75%|███████▌ | 249/331 [00:20<00:11, 7.38it/s]
76%|███████▌ | 250/331 [00:20<00:10, 7.37it/s]
76%|███████▌ | 251/331 [00:20<00:10, 7.39it/s]
76%|███████▌ | 252/331 [00:20<00:10, 7.38it/s]
76%|███████▋ | 253/331 [00:21<00:10, 7.31it/s]
77%|███████▋ | 254/331 [00:21<00:10, 7.31it/s]
77%|███████▋ | 255/331 [00:21<00:10, 7.32it/s]
77%|███████▋ | 256/331 [00:21<00:10, 7.36it/s]
78%|███████▊ | 257/331 [00:21<00:10, 7.28it/s]
78%|███████▊ | 258/331 [00:21<00:10, 7.26it/s]
78%|███████▊ | 259/331 [00:21<00:09, 7.29it/s]
79%|███████▊ | 260/331 [00:21<00:09, 7.28it/s]
79%|███████▉ | 261/331 [00:22<00:09, 7.21it/s]
79%|███████▉ | 262/331 [00:22<00:09, 7.19it/s]
79%|███████▉ | 263/331 [00:22<00:09, 7.20it/s]
80%|███████▉ | 264/331 [00:22<00:09, 7.22it/s]
80%|████████ | 265/331 [00:22<00:09, 7.17it/s]
80%|████████ | 266/331 [00:22<00:09, 7.18it/s]
81%|████████ | 267/331 [00:22<00:08, 7.21it/s]
81%|████████ | 268/331 [00:23<00:08, 7.23it/s]
81%|████████▏ | 269/331 [00:23<00:08, 7.18it/s]
82%|████████▏ | 270/331 [00:23<00:08, 7.19it/s]
82%|████████▏ | 271/331 [00:23<00:08, 7.24it/s]
82%|████████▏ | 272/331 [00:23<00:08, 7.29it/s]
82%|████████▏ | 273/331 [00:23<00:08, 7.21it/s]
83%|████████▎ | 274/331 [00:23<00:07, 7.24it/s]
83%|████████▎ | 275/331 [00:24<00:07, 7.29it/s]
83%|████████▎ | 276/331 [00:24<00:07, 7.34it/s]
84%|████████▎ | 277/331 [00:24<00:07, 7.30it/s]
84%|████████▍ | 278/331 [00:24<00:07, 7.38it/s]
84%|████████▍ | 279/331 [00:24<00:07, 7.43it/s]
85%|████████▍ | 280/331 [00:24<00:06, 7.47it/s]
85%|████████▍ | 281/331 [00:24<00:06, 7.37it/s]
85%|████████▌ | 282/331 [00:25<00:06, 7.40it/s]
85%|████████▌ | 283/331 [00:25<00:06, 7.42it/s]
86%|████████▌ | 284/331 [00:25<00:06, 7.36it/s]
86%|████████▌ | 285/331 [00:25<00:06, 7.33it/s]
86%|████████▋ | 286/331 [00:25<00:06, 7.36it/s]
87%|████████▋ | 287/331 [00:25<00:06, 7.33it/s]
87%|████████▋ | 288/331 [00:25<00:05, 7.41it/s]
87%|████████▋ | 289/331 [00:25<00:05, 7.41it/s]
88%|████████▊ | 290/331 [00:26<00:05, 7.45it/s]
88%|████████▊ | 291/331 [00:26<00:05, 7.52it/s]
88%|████████▊ | 292/331 [00:26<00:05, 7.57it/s]
89%|████████▊ | 293/331 [00:26<00:05, 7.55it/s]
89%|████████▉ | 294/331 [00:26<00:04, 7.61it/s]
89%|████████▉ | 295/331 [00:26<00:04, 7.70it/s]
89%|████████▉ | 296/331 [00:26<00:04, 7.74it/s]
90%|████████▉ | 297/331 [00:26<00:04, 7.65it/s]
90%|█████████ | 298/331 [00:27<00:04, 7.59it/s]
90%|█████████ | 299/331 [00:27<00:04, 7.58it/s]
91%|█████████ | 300/331 [00:27<00:04, 7.55it/s]
91%|█████████ | 301/331 [00:27<00:04, 7.43it/s]
91%|█████████ | 302/331 [00:27<00:03, 7.39it/s]
92%|█████████▏| 303/331 [00:27<00:03, 7.40it/s]
92%|█████████▏| 304/331 [00:27<00:03, 7.38it/s]
92%|█████████▏| 305/331 [00:28<00:03, 7.28it/s]
92%|█████████▏| 306/331 [00:28<00:03, 7.24it/s]
93%|█████████▎| 307/331 [00:28<00:03, 7.23it/s]
93%|█████████▎| 308/331 [00:28<00:03, 7.23it/s]
93%|█████████▎| 309/331 [00:28<00:03, 7.15it/s]
94%|█████████▎| 310/331 [00:28<00:02, 7.12it/s]
94%|█████████▍| 311/331 [00:28<00:02, 7.13it/s]
94%|█████████▍| 312/331 [00:29<00:02, 7.04it/s]
95%|█████████▍| 313/331 [00:29<00:02, 6.99it/s]
95%|█████████▍| 314/331 [00:29<00:02, 6.98it/s]
95%|█████████▌| 315/331 [00:29<00:02, 6.98it/s]
95%|█████████▌| 316/331 [00:29<00:02, 6.96it/s]
96%|█████████▌| 317/331 [00:29<00:02, 6.81it/s]
96%|█████████▌| 318/331 [00:29<00:01, 6.67it/s]
96%|█████████▋| 319/331 [00:30<00:01, 6.52it/s]
97%|█████████▋| 320/331 [00:30<00:01, 6.39it/s]
97%|█████████▋| 321/331 [00:30<00:01, 6.13it/s]
97%|█████████▋| 322/331 [00:30<00:01, 5.85it/s]
98%|█████████▊| 323/331 [00:30<00:01, 5.56it/s]
98%|█████████▊| 324/331 [00:31<00:01, 5.23it/s]
98%|█████████▊| 325/331 [00:31<00:01, 4.89it/s]
98%|█████████▊| 326/331 [00:31<00:01, 4.66it/s]
99%|█████████▉| 327/331 [00:31<00:00, 4.46it/s]
99%|█████████▉| 328/331 [00:32<00:00, 4.29it/s]
99%|█████████▉| 329/331 [00:32<00:00, 4.10it/s]
100%|█████████▉| 330/331 [00:32<00:00, 3.95it/s]
100%|██████████| 331/331 [00:32<00:00, 3.84it/s]
100%|██████████| 331/331 [00:32<00:00, 10.07it/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 36.211 seconds)