Note
Go to the end to download the full example code.
Animate 3D#
Display a labels layer above of an image layer using the add_labels and add_image APIs
Rendering frames...
0%| | 0/151 [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).
1%| | 1/151 [00:00<00:19, 7.57it/s]
2%|▏ | 3/151 [00:00<00:15, 9.80it/s]
3%|▎ | 5/151 [00:00<00:13, 10.91it/s]
5%|▍ | 7/151 [00:00<00:12, 11.83it/s]
6%|▌ | 9/151 [00:00<00:11, 12.73it/s]
7%|▋ | 11/151 [00:00<00:10, 13.64it/s]
9%|▊ | 13/151 [00:01<00:09, 14.52it/s]
10%|▉ | 15/151 [00:01<00:08, 15.33it/s]
11%|█▏ | 17/151 [00:01<00:08, 16.21it/s]
13%|█▎ | 19/151 [00:01<00:07, 16.73it/s]
14%|█▍ | 21/151 [00:01<00:07, 17.09it/s]
15%|█▌ | 23/151 [00:01<00:07, 17.29it/s]
17%|█▋ | 25/151 [00:01<00:07, 17.35it/s]
18%|█▊ | 27/151 [00:01<00:07, 17.29it/s]
19%|█▉ | 29/151 [00:01<00:07, 17.20it/s]
21%|██ | 31/151 [00:02<00:07, 17.03it/s]
22%|██▏ | 33/151 [00:02<00:06, 17.03it/s]
23%|██▎ | 35/151 [00:02<00:06, 16.96it/s]
25%|██▍ | 37/151 [00:02<00:06, 16.79it/s]
26%|██▌ | 39/151 [00:02<00:06, 16.64it/s]
27%|██▋ | 41/151 [00:02<00:06, 16.71it/s]
28%|██▊ | 43/151 [00:02<00:06, 16.15it/s]
30%|██▉ | 45/151 [00:02<00:06, 15.98it/s]
31%|███ | 47/151 [00:03<00:06, 15.97it/s]
32%|███▏ | 49/151 [00:03<00:06, 15.77it/s]
34%|███▍ | 51/151 [00:03<00:06, 15.74it/s]
35%|███▌ | 53/151 [00:03<00:06, 15.57it/s]
36%|███▋ | 55/151 [00:03<00:06, 15.64it/s]
38%|███▊ | 57/151 [00:03<00:06, 15.56it/s]
39%|███▉ | 59/151 [00:03<00:05, 15.72it/s]
40%|████ | 61/151 [00:03<00:05, 15.49it/s]
42%|████▏ | 63/151 [00:04<00:05, 15.27it/s]
43%|████▎ | 65/151 [00:04<00:05, 15.07it/s]
44%|████▍ | 67/151 [00:04<00:05, 15.29it/s]
46%|████▌ | 69/151 [00:04<00:05, 15.20it/s]
47%|████▋ | 71/151 [00:04<00:05, 15.33it/s]
48%|████▊ | 73/151 [00:04<00:05, 15.24it/s]
50%|████▉ | 75/151 [00:04<00:04, 15.33it/s]
51%|█████ | 77/151 [00:04<00:04, 15.12it/s]
52%|█████▏ | 79/151 [00:05<00:04, 15.26it/s]
54%|█████▎ | 81/151 [00:05<00:04, 15.06it/s]
55%|█████▍ | 83/151 [00:05<00:04, 15.13it/s]
56%|█████▋ | 85/151 [00:05<00:04, 14.96it/s]
58%|█████▊ | 87/151 [00:05<00:04, 15.03it/s]
59%|█████▉ | 89/151 [00:05<00:04, 14.87it/s]
60%|██████ | 91/151 [00:05<00:04, 14.96it/s]
62%|██████▏ | 93/151 [00:06<00:03, 14.85it/s]
63%|██████▎ | 95/151 [00:06<00:03, 14.97it/s]
64%|██████▍ | 97/151 [00:06<00:03, 14.46it/s]
66%|██████▌ | 99/151 [00:06<00:03, 14.72it/s]
67%|██████▋ | 101/151 [00:06<00:03, 14.52it/s]
68%|██████▊ | 103/151 [00:06<00:03, 14.57it/s]
70%|██████▉ | 105/151 [00:06<00:03, 14.47it/s]
71%|███████ | 107/151 [00:07<00:02, 14.67it/s]
72%|███████▏ | 109/151 [00:07<00:02, 14.33it/s]
74%|███████▎ | 111/151 [00:07<00:02, 14.65it/s]
75%|███████▍ | 113/151 [00:07<00:02, 14.37it/s]
76%|███████▌ | 115/151 [00:07<00:02, 14.15it/s]
77%|███████▋ | 117/151 [00:07<00:02, 14.29it/s]
79%|███████▉ | 119/151 [00:07<00:02, 14.49it/s]
80%|████████ | 121/151 [00:07<00:02, 14.52it/s]
81%|████████▏ | 123/151 [00:08<00:01, 14.64it/s]
83%|████████▎ | 125/151 [00:08<00:01, 14.26it/s]
84%|████████▍ | 127/151 [00:08<00:01, 14.16it/s]
85%|████████▌ | 129/151 [00:08<00:01, 14.08it/s]
87%|████████▋ | 131/151 [00:08<00:01, 14.06it/s]
88%|████████▊ | 133/151 [00:08<00:01, 13.99it/s]
89%|████████▉ | 135/151 [00:08<00:01, 14.13it/s]
91%|█████████ | 137/151 [00:09<00:01, 13.81it/s]
92%|█████████▏| 139/151 [00:09<00:00, 13.42it/s]
93%|█████████▎| 141/151 [00:09<00:00, 12.60it/s]
95%|█████████▍| 143/151 [00:09<00:00, 11.99it/s]
96%|█████████▌| 145/151 [00:09<00:00, 10.89it/s]
97%|█████████▋| 147/151 [00:10<00:00, 10.18it/s]
99%|█████████▊| 149/151 [00:10<00:00, 9.43it/s]
99%|█████████▉| 150/151 [00:10<00:00, 9.17it/s]
100%|██████████| 151/151 [00:10<00:00, 8.97it/s]
100%|██████████| 151/151 [00:10<00:00, 14.23it/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})
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("animate3D.mp4", canvas_only=False)
Total running time of the script: (0 minutes 13.876 seconds)