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 (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/151 [00:00<01:42,  1.46it/s]
  1%|▏         | 2/151 [00:01<01:36,  1.54it/s]
  2%|▏         | 3/151 [00:01<01:30,  1.63it/s]
  3%|▎         | 4/151 [00:02<01:26,  1.71it/s]
  3%|▎         | 5/151 [00:02<01:22,  1.77it/s]
  4%|▍         | 6/151 [00:03<01:17,  1.87it/s]
  5%|▍         | 7/151 [00:03<01:12,  1.98it/s]
  5%|▌         | 8/151 [00:04<01:08,  2.09it/s]
  6%|▌         | 9/151 [00:04<01:04,  2.22it/s]
  7%|▋         | 10/151 [00:05<00:59,  2.35it/s]
  7%|▋         | 11/151 [00:05<00:56,  2.48it/s]
  8%|▊         | 12/151 [00:05<00:52,  2.63it/s]
  9%|▊         | 13/151 [00:06<00:49,  2.78it/s]
  9%|▉         | 14/151 [00:06<00:46,  2.94it/s]
 10%|▉         | 15/151 [00:06<00:43,  3.12it/s]
 11%|█         | 16/151 [00:06<00:41,  3.29it/s]
 11%|█▏        | 17/151 [00:07<00:39,  3.42it/s]
 12%|█▏        | 18/151 [00:07<00:38,  3.48it/s]
 13%|█▎        | 19/151 [00:07<00:37,  3.53it/s]
 13%|█▎        | 20/151 [00:07<00:36,  3.58it/s]
 14%|█▍        | 21/151 [00:08<00:36,  3.57it/s]
 15%|█▍        | 22/151 [00:08<00:36,  3.57it/s]
 15%|█▌        | 23/151 [00:08<00:35,  3.58it/s]
 16%|█▌        | 24/151 [00:09<00:35,  3.58it/s]
 17%|█▋        | 25/151 [00:09<00:35,  3.57it/s]
 17%|█▋        | 26/151 [00:09<00:34,  3.57it/s]
 18%|█▊        | 27/151 [00:09<00:34,  3.58it/s]
 19%|█▊        | 28/151 [00:10<00:34,  3.58it/s]
 19%|█▉        | 29/151 [00:10<00:34,  3.56it/s]
 20%|█▉        | 30/151 [00:10<00:34,  3.55it/s]
 21%|██        | 31/151 [00:11<00:33,  3.55it/s]
 21%|██        | 32/151 [00:11<00:33,  3.54it/s]
 22%|██▏       | 33/151 [00:11<00:33,  3.50it/s]
 23%|██▎       | 34/151 [00:11<00:33,  3.47it/s]
 23%|██▎       | 35/151 [00:12<00:33,  3.47it/s]
 24%|██▍       | 36/151 [00:12<00:33,  3.45it/s]
 25%|██▍       | 37/151 [00:12<00:32,  3.46it/s]
 25%|██▌       | 38/151 [00:13<00:32,  3.46it/s]
 26%|██▌       | 39/151 [00:13<00:32,  3.44it/s]
 26%|██▋       | 40/151 [00:13<00:32,  3.43it/s]
 27%|██▋       | 41/151 [00:13<00:32,  3.43it/s]
 28%|██▊       | 42/151 [00:14<00:31,  3.43it/s]
 28%|██▊       | 43/151 [00:14<00:32,  3.33it/s]
 29%|██▉       | 44/151 [00:14<00:31,  3.35it/s]
 30%|██▉       | 45/151 [00:15<00:31,  3.36it/s]
 30%|███       | 46/151 [00:15<00:31,  3.36it/s]
 31%|███       | 47/151 [00:15<00:31,  3.34it/s]
 32%|███▏      | 48/151 [00:16<00:31,  3.32it/s]
 32%|███▏      | 49/151 [00:16<00:30,  3.32it/s]
 33%|███▎      | 50/151 [00:16<00:30,  3.30it/s]
 34%|███▍      | 51/151 [00:16<00:30,  3.29it/s]
 34%|███▍      | 52/151 [00:17<00:30,  3.28it/s]
 35%|███▌      | 53/151 [00:17<00:30,  3.25it/s]
 36%|███▌      | 54/151 [00:17<00:30,  3.23it/s]
 36%|███▋      | 55/151 [00:18<00:29,  3.23it/s]
 37%|███▋      | 56/151 [00:18<00:29,  3.24it/s]
 38%|███▊      | 57/151 [00:18<00:29,  3.23it/s]
 38%|███▊      | 58/151 [00:19<00:28,  3.24it/s]
 39%|███▉      | 59/151 [00:19<00:28,  3.25it/s]
 40%|███▉      | 60/151 [00:19<00:28,  3.23it/s]
 40%|████      | 61/151 [00:20<00:27,  3.22it/s]
 41%|████      | 62/151 [00:20<00:27,  3.21it/s]
 42%|████▏     | 63/151 [00:20<00:27,  3.21it/s]
 42%|████▏     | 64/151 [00:21<00:27,  3.21it/s]
 43%|████▎     | 65/151 [00:21<00:26,  3.19it/s]
 44%|████▎     | 66/151 [00:21<00:27,  3.07it/s]
 44%|████▍     | 67/151 [00:22<00:26,  3.11it/s]
 45%|████▌     | 68/151 [00:22<00:26,  3.13it/s]
 46%|████▌     | 69/151 [00:22<00:26,  3.14it/s]
 46%|████▋     | 70/151 [00:22<00:25,  3.15it/s]
 47%|████▋     | 71/151 [00:23<00:25,  3.17it/s]
 48%|████▊     | 72/151 [00:23<00:24,  3.18it/s]
 48%|████▊     | 73/151 [00:23<00:24,  3.17it/s]
 49%|████▉     | 74/151 [00:24<00:24,  3.16it/s]
 50%|████▉     | 75/151 [00:24<00:23,  3.18it/s]
 50%|█████     | 76/151 [00:24<00:23,  3.19it/s]
 51%|█████     | 77/151 [00:25<00:23,  3.18it/s]
 52%|█████▏    | 78/151 [00:25<00:22,  3.18it/s]
 52%|█████▏    | 79/151 [00:25<00:22,  3.18it/s]
 53%|█████▎    | 80/151 [00:26<00:22,  3.17it/s]
 54%|█████▎    | 81/151 [00:26<00:22,  3.13it/s]
 54%|█████▍    | 82/151 [00:26<00:21,  3.14it/s]
 55%|█████▍    | 83/151 [00:27<00:21,  3.16it/s]
 56%|█████▌    | 84/151 [00:27<00:21,  3.16it/s]
 56%|█████▋    | 85/151 [00:27<00:20,  3.16it/s]
 57%|█████▋    | 86/151 [00:28<00:20,  3.16it/s]
 58%|█████▊    | 87/151 [00:28<00:20,  3.18it/s]
 58%|█████▊    | 88/151 [00:28<00:19,  3.20it/s]
 59%|█████▉    | 89/151 [00:28<00:19,  3.20it/s]
 60%|█████▉    | 90/151 [00:29<00:18,  3.22it/s]
 60%|██████    | 91/151 [00:29<00:18,  3.25it/s]
 61%|██████    | 92/151 [00:29<00:18,  3.26it/s]
 62%|██████▏   | 93/151 [00:30<00:17,  3.27it/s]
 62%|██████▏   | 94/151 [00:30<00:17,  3.28it/s]
 63%|██████▎   | 95/151 [00:30<00:16,  3.32it/s]
 64%|██████▎   | 96/151 [00:31<00:16,  3.34it/s]
 64%|██████▍   | 97/151 [00:31<00:16,  3.34it/s]
 65%|██████▍   | 98/151 [00:31<00:15,  3.34it/s]
 66%|██████▌   | 99/151 [00:31<00:15,  3.36it/s]
 66%|██████▌   | 100/151 [00:32<00:15,  3.37it/s]
 67%|██████▋   | 101/151 [00:32<00:14,  3.36it/s]
 68%|██████▊   | 102/151 [00:32<00:14,  3.38it/s]
 68%|██████▊   | 103/151 [00:33<00:14,  3.37it/s]
 69%|██████▉   | 104/151 [00:33<00:13,  3.40it/s]
 70%|██████▉   | 105/151 [00:33<00:13,  3.40it/s]
 70%|███████   | 106/151 [00:33<00:13,  3.41it/s]
 71%|███████   | 107/151 [00:34<00:12,  3.44it/s]
 72%|███████▏  | 108/151 [00:34<00:12,  3.45it/s]
 72%|███████▏  | 109/151 [00:34<00:12,  3.44it/s]
 73%|███████▎  | 110/151 [00:35<00:11,  3.44it/s]
 74%|███████▎  | 111/151 [00:35<00:11,  3.45it/s]
 74%|███████▍  | 112/151 [00:35<00:11,  3.46it/s]
 75%|███████▍  | 113/151 [00:36<00:11,  3.44it/s]
 75%|███████▌  | 114/151 [00:36<00:10,  3.47it/s]
 76%|███████▌  | 115/151 [00:36<00:10,  3.51it/s]
 77%|███████▋  | 116/151 [00:36<00:09,  3.51it/s]
 77%|███████▋  | 117/151 [00:37<00:09,  3.49it/s]
 78%|███████▊  | 118/151 [00:37<00:09,  3.48it/s]
 79%|███████▉  | 119/151 [00:37<00:09,  3.48it/s]
 79%|███████▉  | 120/151 [00:38<00:08,  3.45it/s]
 80%|████████  | 121/151 [00:38<00:08,  3.42it/s]
 81%|████████  | 122/151 [00:38<00:08,  3.39it/s]
 81%|████████▏ | 123/151 [00:38<00:08,  3.36it/s]
 82%|████████▏ | 124/151 [00:39<00:08,  3.35it/s]
 83%|████████▎ | 125/151 [00:39<00:07,  3.32it/s]
 83%|████████▎ | 126/151 [00:39<00:07,  3.30it/s]
 84%|████████▍ | 127/151 [00:40<00:07,  3.28it/s]
 85%|████████▍ | 128/151 [00:40<00:07,  3.27it/s]
 85%|████████▌ | 129/151 [00:40<00:06,  3.24it/s]
 86%|████████▌ | 130/151 [00:41<00:06,  3.21it/s]
 87%|████████▋ | 131/151 [00:41<00:06,  3.21it/s]
 87%|████████▋ | 132/151 [00:41<00:05,  3.21it/s]
 88%|████████▊ | 133/151 [00:42<00:05,  3.17it/s]
 89%|████████▊ | 134/151 [00:42<00:05,  3.17it/s]
 89%|████████▉ | 135/151 [00:42<00:05,  3.15it/s]
 90%|█████████ | 136/151 [00:42<00:04,  3.14it/s]
 91%|█████████ | 137/151 [00:43<00:04,  3.08it/s]
 91%|█████████▏| 138/151 [00:43<00:04,  3.03it/s]
 92%|█████████▏| 139/151 [00:44<00:04,  2.96it/s]
 93%|█████████▎| 140/151 [00:44<00:03,  2.90it/s]
 93%|█████████▎| 141/151 [00:44<00:03,  2.78it/s]
 94%|█████████▍| 142/151 [00:45<00:03,  2.64it/s]
 95%|█████████▍| 143/151 [00:45<00:03,  2.48it/s]
 95%|█████████▌| 144/151 [00:46<00:03,  2.32it/s]
 96%|█████████▌| 145/151 [00:46<00:02,  2.17it/s]
 97%|█████████▋| 146/151 [00:47<00:02,  2.03it/s]
 97%|█████████▋| 147/151 [00:47<00:02,  1.90it/s]
 98%|█████████▊| 148/151 [00:48<00:01,  1.80it/s]
 99%|█████████▊| 149/151 [00:49<00:01,  1.73it/s]
 99%|█████████▉| 150/151 [00:49<00:00,  1.66it/s]
100%|██████████| 151/151 [00:50<00:00,  1.63it/s]
100%|██████████| 151/151 [00:50<00:00,  2.99it/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})

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 55.564 seconds)

Gallery generated by Sphinx-Gallery