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<01:19,  4.13it/s]
  2%|▏         | 5/331 [00:00<00:19, 16.62it/s]
  3%|▎         | 10/331 [00:00<00:12, 26.05it/s]
  5%|▍         | 15/331 [00:00<00:09, 32.28it/s]
  6%|▌         | 19/331 [00:00<00:09, 34.39it/s]
  7%|▋         | 23/331 [00:00<00:08, 35.61it/s]
  8%|▊         | 27/331 [00:00<00:08, 36.30it/s]
  9%|▉         | 31/331 [00:01<00:08, 36.49it/s]
 11%|█         | 35/331 [00:01<00:09, 30.43it/s]
 12%|█▏        | 39/331 [00:01<00:10, 26.71it/s]
 13%|█▎        | 42/331 [00:01<00:11, 25.35it/s]
 14%|█▎        | 45/331 [00:01<00:12, 22.28it/s]
 15%|█▍        | 48/331 [00:01<00:13, 21.59it/s]
 15%|█▌        | 51/331 [00:01<00:12, 22.03it/s]
 16%|█▋        | 54/331 [00:02<00:12, 21.82it/s]
 17%|█▋        | 57/331 [00:02<00:12, 21.81it/s]
 18%|█▊        | 60/331 [00:02<00:12, 21.53it/s]
 19%|█▉        | 63/331 [00:02<00:12, 21.52it/s]
 20%|█▉        | 66/331 [00:02<00:12, 21.55it/s]
 21%|██        | 69/331 [00:02<00:12, 21.62it/s]
 22%|██▏       | 72/331 [00:02<00:12, 21.58it/s]
 23%|██▎       | 75/331 [00:03<00:12, 21.00it/s]
 24%|██▎       | 78/331 [00:03<00:12, 20.95it/s]
 24%|██▍       | 81/331 [00:03<00:11, 21.09it/s]
 25%|██▌       | 84/331 [00:03<00:11, 21.28it/s]
 26%|██▋       | 87/331 [00:03<00:11, 21.31it/s]
 27%|██▋       | 90/331 [00:03<00:11, 21.31it/s]
 28%|██▊       | 93/331 [00:03<00:10, 23.06it/s]
 29%|██▉       | 96/331 [00:04<00:09, 24.33it/s]
 30%|██▉       | 99/331 [00:04<00:09, 25.21it/s]
 31%|███       | 102/331 [00:04<00:08, 25.94it/s]
 32%|███▏      | 105/331 [00:04<00:08, 26.30it/s]
 33%|███▎      | 108/331 [00:04<00:08, 26.90it/s]
 34%|███▎      | 111/331 [00:04<00:08, 27.18it/s]
 34%|███▍      | 114/331 [00:04<00:08, 27.09it/s]
 35%|███▌      | 117/331 [00:04<00:07, 27.10it/s]
 36%|███▋      | 120/331 [00:04<00:07, 27.26it/s]
 37%|███▋      | 123/331 [00:05<00:07, 26.36it/s]
 38%|███▊      | 126/331 [00:05<00:07, 26.55it/s]
 39%|███▉      | 129/331 [00:05<00:07, 26.82it/s]
 40%|███▉      | 132/331 [00:05<00:07, 26.90it/s]
 41%|████      | 135/331 [00:05<00:07, 27.00it/s]
 42%|████▏     | 138/331 [00:05<00:07, 27.08it/s]
 43%|████▎     | 141/331 [00:05<00:06, 27.26it/s]
 44%|████▎     | 144/331 [00:05<00:06, 27.64it/s]
 44%|████▍     | 147/331 [00:05<00:06, 27.39it/s]
 45%|████▌     | 150/331 [00:06<00:06, 27.01it/s]
 47%|████▋     | 154/331 [00:06<00:06, 28.60it/s]
 48%|████▊     | 158/331 [00:06<00:05, 30.16it/s]
 49%|████▉     | 162/331 [00:06<00:05, 30.71it/s]
 50%|█████     | 166/331 [00:06<00:05, 31.46it/s]
 51%|█████▏    | 170/331 [00:09<00:37,  4.31it/s]
 52%|█████▏    | 173/331 [00:11<00:52,  2.99it/s]
 53%|█████▎    | 175/331 [00:12<01:01,  2.54it/s]
 53%|█████▎    | 177/331 [00:13<01:09,  2.23it/s]
 54%|█████▍    | 178/331 [00:14<01:12,  2.11it/s]
 54%|█████▍    | 179/331 [00:14<01:16,  1.99it/s]
 54%|█████▍    | 180/331 [00:15<01:19,  1.89it/s]
 55%|█████▍    | 181/331 [00:16<01:22,  1.82it/s]
 55%|█████▍    | 182/331 [00:16<01:23,  1.78it/s]
 55%|█████▌    | 183/331 [00:17<01:23,  1.78it/s]
 56%|█████▌    | 184/331 [00:17<01:21,  1.81it/s]
 56%|█████▌    | 185/331 [00:18<01:18,  1.87it/s]
 56%|█████▌    | 186/331 [00:18<01:15,  1.93it/s]
 56%|█████▋    | 187/331 [00:19<01:11,  2.01it/s]
 57%|█████▋    | 188/331 [00:19<01:08,  2.10it/s]
 57%|█████▋    | 189/331 [00:20<01:03,  2.22it/s]
 57%|█████▋    | 190/331 [00:20<01:00,  2.34it/s]
 58%|█████▊    | 191/331 [00:20<00:56,  2.48it/s]
 58%|█████▊    | 192/331 [00:21<00:52,  2.64it/s]
 58%|█████▊    | 193/331 [00:21<00:49,  2.81it/s]
 59%|█████▊    | 194/331 [00:21<00:46,  2.96it/s]
 59%|█████▉    | 195/331 [00:22<00:43,  3.15it/s]
 59%|█████▉    | 196/331 [00:22<00:40,  3.34it/s]
 60%|█████▉    | 197/331 [00:22<00:38,  3.47it/s]
 60%|█████▉    | 198/331 [00:22<00:37,  3.53it/s]
 60%|██████    | 199/331 [00:23<00:36,  3.58it/s]
 60%|██████    | 200/331 [00:23<00:36,  3.63it/s]
 61%|██████    | 201/331 [00:23<00:35,  3.64it/s]
 61%|██████    | 202/331 [00:23<00:35,  3.67it/s]
 61%|██████▏   | 203/331 [00:24<00:34,  3.67it/s]
 62%|██████▏   | 204/331 [00:24<00:34,  3.64it/s]
 62%|██████▏   | 205/331 [00:24<00:34,  3.61it/s]
 62%|██████▏   | 206/331 [00:25<00:34,  3.60it/s]
 63%|██████▎   | 207/331 [00:25<00:34,  3.58it/s]
 63%|██████▎   | 208/331 [00:25<00:34,  3.58it/s]
 63%|██████▎   | 209/331 [00:25<00:34,  3.52it/s]
 63%|██████▎   | 210/331 [00:26<00:34,  3.53it/s]
 64%|██████▎   | 211/331 [00:26<00:33,  3.54it/s]
 64%|██████▍   | 212/331 [00:26<00:33,  3.55it/s]
 64%|██████▍   | 213/331 [00:27<00:33,  3.53it/s]
 65%|██████▍   | 214/331 [00:27<00:33,  3.52it/s]
 65%|██████▍   | 215/331 [00:27<00:32,  3.52it/s]
 65%|██████▌   | 216/331 [00:27<00:32,  3.50it/s]
 66%|██████▌   | 217/331 [00:28<00:32,  3.50it/s]
 66%|██████▌   | 218/331 [00:28<00:32,  3.49it/s]
 66%|██████▌   | 219/331 [00:28<00:32,  3.48it/s]
 66%|██████▋   | 220/331 [00:29<00:32,  3.45it/s]
 67%|██████▋   | 221/331 [00:29<00:31,  3.46it/s]
 67%|██████▋   | 222/331 [00:29<00:31,  3.43it/s]
 67%|██████▋   | 223/331 [00:29<00:31,  3.43it/s]
 68%|██████▊   | 224/331 [00:30<00:31,  3.42it/s]
 68%|██████▊   | 225/331 [00:30<00:31,  3.40it/s]
 68%|██████▊   | 226/331 [00:30<00:30,  3.39it/s]
 69%|██████▊   | 227/331 [00:31<00:30,  3.38it/s]
 69%|██████▉   | 228/331 [00:31<00:30,  3.36it/s]
 69%|██████▉   | 229/331 [00:31<00:30,  3.35it/s]
 69%|██████▉   | 230/331 [00:32<00:30,  3.34it/s]
 70%|██████▉   | 231/331 [00:32<00:30,  3.32it/s]
 70%|███████   | 232/331 [00:32<00:30,  3.22it/s]
 70%|███████   | 233/331 [00:32<00:30,  3.16it/s]
 71%|███████   | 234/331 [00:33<00:30,  3.20it/s]
 71%|███████   | 235/331 [00:33<00:29,  3.24it/s]
 71%|███████▏  | 236/331 [00:33<00:29,  3.25it/s]
 72%|███████▏  | 237/331 [00:34<00:28,  3.25it/s]
 72%|███████▏  | 238/331 [00:34<00:28,  3.24it/s]
 72%|███████▏  | 239/331 [00:34<00:28,  3.27it/s]
 73%|███████▎  | 240/331 [00:35<00:27,  3.26it/s]
 73%|███████▎  | 241/331 [00:35<00:27,  3.26it/s]
 73%|███████▎  | 242/331 [00:35<00:27,  3.25it/s]
 73%|███████▎  | 243/331 [00:36<00:27,  3.25it/s]
 74%|███████▎  | 244/331 [00:36<00:26,  3.25it/s]
 74%|███████▍  | 245/331 [00:36<00:26,  3.23it/s]
 74%|███████▍  | 246/331 [00:36<00:26,  3.23it/s]
 75%|███████▍  | 247/331 [00:37<00:25,  3.24it/s]
 75%|███████▍  | 248/331 [00:37<00:25,  3.21it/s]
 75%|███████▌  | 249/331 [00:37<00:25,  3.21it/s]
 76%|███████▌  | 250/331 [00:38<00:25,  3.19it/s]
 76%|███████▌  | 251/331 [00:38<00:25,  3.18it/s]
 76%|███████▌  | 252/331 [00:38<00:24,  3.17it/s]
 76%|███████▋  | 253/331 [00:39<00:24,  3.15it/s]
 77%|███████▋  | 254/331 [00:39<00:24,  3.16it/s]
 77%|███████▋  | 255/331 [00:39<00:24,  3.16it/s]
 77%|███████▋  | 256/331 [00:40<00:23,  3.14it/s]
 78%|███████▊  | 257/331 [00:40<00:23,  3.14it/s]
 78%|███████▊  | 258/331 [00:40<00:23,  3.15it/s]
 78%|███████▊  | 259/331 [00:41<00:22,  3.15it/s]
 79%|███████▊  | 260/331 [00:41<00:22,  3.14it/s]
 79%|███████▉  | 261/331 [00:41<00:22,  3.13it/s]
 79%|███████▉  | 262/331 [00:42<00:22,  3.14it/s]
 79%|███████▉  | 263/331 [00:42<00:21,  3.13it/s]
 80%|███████▉  | 264/331 [00:42<00:21,  3.11it/s]
 80%|████████  | 265/331 [00:43<00:21,  3.12it/s]
 80%|████████  | 266/331 [00:43<00:20,  3.12it/s]
 81%|████████  | 267/331 [00:43<00:20,  3.12it/s]
 81%|████████  | 268/331 [00:43<00:20,  3.11it/s]
 81%|████████▏ | 269/331 [00:44<00:19,  3.11it/s]
 82%|████████▏ | 270/331 [00:44<00:19,  3.12it/s]
 82%|████████▏ | 271/331 [00:44<00:19,  3.14it/s]
 82%|████████▏ | 272/331 [00:45<00:18,  3.15it/s]
 82%|████████▏ | 273/331 [00:45<00:18,  3.17it/s]
 83%|████████▎ | 274/331 [00:45<00:17,  3.17it/s]
 83%|████████▎ | 275/331 [00:46<00:17,  3.19it/s]
 83%|████████▎ | 276/331 [00:46<00:17,  3.19it/s]
 84%|████████▎ | 277/331 [00:46<00:16,  3.21it/s]
 84%|████████▍ | 278/331 [00:47<00:16,  3.21it/s]
 84%|████████▍ | 279/331 [00:47<00:16,  3.22it/s]
 85%|████████▍ | 280/331 [00:47<00:15,  3.22it/s]
 85%|████████▍ | 281/331 [00:48<00:15,  3.20it/s]
 85%|████████▌ | 282/331 [00:48<00:15,  3.23it/s]
 85%|████████▌ | 283/331 [00:48<00:14,  3.25it/s]
 86%|████████▌ | 284/331 [00:48<00:14,  3.24it/s]
 86%|████████▌ | 285/331 [00:49<00:14,  3.25it/s]
 86%|████████▋ | 286/331 [00:49<00:13,  3.26it/s]
 87%|████████▋ | 287/331 [00:49<00:13,  3.27it/s]
 87%|████████▋ | 288/331 [00:50<00:13,  3.26it/s]
 87%|████████▋ | 289/331 [00:50<00:12,  3.27it/s]
 88%|████████▊ | 290/331 [00:50<00:12,  3.28it/s]
 88%|████████▊ | 291/331 [00:51<00:12,  3.31it/s]
 88%|████████▊ | 292/331 [00:51<00:11,  3.30it/s]
 89%|████████▊ | 293/331 [00:51<00:11,  3.32it/s]
 89%|████████▉ | 294/331 [00:51<00:11,  3.35it/s]
 89%|████████▉ | 295/331 [00:52<00:10,  3.36it/s]
 89%|████████▉ | 296/331 [00:52<00:10,  3.35it/s]
 90%|████████▉ | 297/331 [00:52<00:10,  3.34it/s]
 90%|█████████ | 298/331 [00:53<00:10,  3.27it/s]
 90%|█████████ | 299/331 [00:53<00:09,  3.27it/s]
 91%|█████████ | 300/331 [00:53<00:09,  3.25it/s]
 91%|█████████ | 301/331 [00:54<00:09,  3.24it/s]
 91%|█████████ | 302/331 [00:54<00:08,  3.24it/s]
 92%|█████████▏| 303/331 [00:54<00:08,  3.23it/s]
 92%|█████████▏| 304/331 [00:55<00:08,  3.21it/s]
 92%|█████████▏| 305/331 [00:55<00:08,  3.19it/s]
 92%|█████████▏| 306/331 [00:55<00:07,  3.19it/s]
 93%|█████████▎| 307/331 [00:56<00:07,  3.18it/s]
 93%|█████████▎| 308/331 [00:56<00:07,  3.14it/s]
 93%|█████████▎| 309/331 [00:56<00:07,  3.13it/s]
 94%|█████████▎| 310/331 [00:56<00:06,  3.13it/s]
 94%|█████████▍| 311/331 [00:57<00:06,  3.10it/s]
 94%|█████████▍| 312/331 [00:57<00:06,  3.09it/s]
 95%|█████████▍| 313/331 [00:57<00:05,  3.09it/s]
 95%|█████████▍| 314/331 [00:58<00:05,  3.10it/s]
 95%|█████████▌| 315/331 [00:58<00:05,  3.08it/s]
 95%|█████████▌| 316/331 [00:58<00:04,  3.08it/s]
 96%|█████████▌| 317/331 [00:59<00:04,  3.03it/s]
 96%|█████████▌| 318/331 [00:59<00:04,  2.95it/s]
 96%|█████████▋| 319/331 [01:00<00:04,  2.87it/s]
 97%|█████████▋| 320/331 [01:00<00:03,  2.79it/s]
 97%|█████████▋| 321/331 [01:00<00:03,  2.68it/s]
 97%|█████████▋| 322/331 [01:01<00:03,  2.52it/s]
 98%|█████████▊| 323/331 [01:01<00:03,  2.38it/s]
 98%|█████████▊| 324/331 [01:02<00:03,  2.22it/s]
 98%|█████████▊| 325/331 [01:02<00:02,  2.08it/s]
 98%|█████████▊| 326/331 [01:03<00:02,  1.97it/s]
 99%|█████████▉| 327/331 [01:03<00:02,  1.89it/s]
 99%|█████████▉| 328/331 [01:04<00:01,  1.80it/s]
 99%|█████████▉| 329/331 [01:05<00:01,  1.73it/s]
100%|█████████▉| 330/331 [01:05<00:00,  1.67it/s]
100%|██████████| 331/331 [01:06<00:00,  1.64it/s]
100%|██████████| 331/331 [01:06<00:00,  4.98it/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: (1 minutes 10.672 seconds)

Gallery generated by Sphinx-Gallery