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:21,  4.04it/s]
  2%|▏         | 5/331 [00:00<00:20, 15.55it/s]
  3%|▎         | 9/331 [00:00<00:13, 23.32it/s]
  4%|▍         | 14/331 [00:00<00:10, 29.36it/s]
  5%|▌         | 18/331 [00:00<00:09, 32.40it/s]
  7%|▋         | 22/331 [00:00<00:09, 33.85it/s]
  8%|▊         | 26/331 [00:00<00:08, 34.62it/s]
  9%|▉         | 30/331 [00:01<00:08, 34.41it/s]
 10%|█         | 34/331 [00:01<00:09, 30.84it/s]
 11%|█▏        | 38/331 [00:01<00:10, 27.69it/s]
 12%|█▏        | 41/331 [00:01<00:11, 26.20it/s]
 13%|█▎        | 44/331 [00:01<00:12, 23.65it/s]
 14%|█▍        | 47/331 [00:01<00:12, 22.88it/s]
 15%|█▌        | 50/331 [00:01<00:12, 22.43it/s]
 16%|█▌        | 53/331 [00:02<00:12, 22.57it/s]
 17%|█▋        | 56/331 [00:02<00:12, 22.49it/s]
 18%|█▊        | 59/331 [00:02<00:12, 22.45it/s]
 19%|█▊        | 62/331 [00:02<00:12, 22.37it/s]
 20%|█▉        | 65/331 [00:02<00:11, 22.29it/s]
 21%|██        | 68/331 [00:02<00:11, 22.33it/s]
 21%|██▏       | 71/331 [00:02<00:11, 22.32it/s]
 22%|██▏       | 74/331 [00:03<00:11, 22.12it/s]
 23%|██▎       | 77/331 [00:03<00:11, 21.97it/s]
 24%|██▍       | 80/331 [00:03<00:11, 22.12it/s]
 25%|██▌       | 83/331 [00:03<00:11, 22.13it/s]
 26%|██▌       | 86/331 [00:03<00:11, 21.87it/s]
 27%|██▋       | 89/331 [00:03<00:10, 22.09it/s]
 28%|██▊       | 92/331 [00:03<00:10, 23.23it/s]
 29%|██▊       | 95/331 [00:03<00:09, 24.50it/s]
 30%|██▉       | 98/331 [00:04<00:09, 25.44it/s]
 31%|███       | 101/331 [00:04<00:08, 26.22it/s]
 31%|███▏      | 104/331 [00:04<00:08, 26.96it/s]
 32%|███▏      | 107/331 [00:04<00:08, 27.27it/s]
 33%|███▎      | 110/331 [00:04<00:08, 27.56it/s]
 34%|███▍      | 113/331 [00:04<00:07, 27.74it/s]
 35%|███▌      | 116/331 [00:04<00:07, 27.86it/s]
 36%|███▌      | 119/331 [00:04<00:07, 27.77it/s]
 37%|███▋      | 122/331 [00:04<00:07, 27.05it/s]
 38%|███▊      | 125/331 [00:05<00:07, 27.02it/s]
 39%|███▊      | 128/331 [00:05<00:07, 27.58it/s]
 40%|███▉      | 131/331 [00:05<00:07, 27.41it/s]
 40%|████      | 134/331 [00:05<00:07, 27.59it/s]
 41%|████▏     | 137/331 [00:05<00:07, 27.64it/s]
 42%|████▏     | 140/331 [00:05<00:06, 27.54it/s]
 43%|████▎     | 143/331 [00:05<00:06, 27.06it/s]
 44%|████▍     | 146/331 [00:05<00:06, 27.49it/s]
 45%|████▌     | 149/331 [00:05<00:06, 27.38it/s]
 46%|████▌     | 152/331 [00:05<00:06, 27.65it/s]
 47%|████▋     | 156/331 [00:06<00:06, 29.03it/s]
 48%|████▊     | 160/331 [00:06<00:05, 29.72it/s]
 50%|████▉     | 164/331 [00:06<00:05, 30.48it/s]
 51%|█████     | 168/331 [00:06<00:09, 17.52it/s]
 52%|█████▏    | 171/331 [00:07<00:12, 12.87it/s]
 52%|█████▏    | 173/331 [00:07<00:14, 11.22it/s]
 53%|█████▎    | 175/331 [00:07<00:15,  9.98it/s]
 53%|█████▎    | 177/331 [00:08<00:16,  9.15it/s]
 54%|█████▍    | 179/331 [00:08<00:17,  8.47it/s]
 54%|█████▍    | 180/331 [00:08<00:18,  8.21it/s]
 55%|█████▍    | 181/331 [00:08<00:18,  8.05it/s]
 55%|█████▍    | 182/331 [00:08<00:18,  8.01it/s]
 55%|█████▌    | 183/331 [00:08<00:18,  8.03it/s]
 56%|█████▌    | 184/331 [00:08<00:18,  8.15it/s]
 56%|█████▌    | 185/331 [00:09<00:17,  8.32it/s]
 56%|█████▌    | 186/331 [00:09<00:16,  8.57it/s]
 56%|█████▋    | 187/331 [00:09<00:16,  8.88it/s]
 57%|█████▋    | 189/331 [00:09<00:14,  9.64it/s]
 58%|█████▊    | 191/331 [00:09<00:13, 10.24it/s]
 58%|█████▊    | 193/331 [00:09<00:12, 10.82it/s]
 59%|█████▉    | 195/331 [00:09<00:11, 11.47it/s]
 60%|█████▉    | 197/331 [00:10<00:10, 12.46it/s]
 60%|██████    | 199/331 [00:10<00:10, 13.08it/s]
 61%|██████    | 201/331 [00:10<00:09, 13.54it/s]
 61%|██████▏   | 203/331 [00:10<00:09, 13.81it/s]
 62%|██████▏   | 205/331 [00:10<00:09, 13.99it/s]
 63%|██████▎   | 207/331 [00:10<00:08, 14.06it/s]
 63%|██████▎   | 209/331 [00:10<00:08, 14.13it/s]
 64%|██████▎   | 211/331 [00:11<00:08, 14.09it/s]
 64%|██████▍   | 213/331 [00:11<00:08, 13.97it/s]
 65%|██████▍   | 215/331 [00:11<00:08, 13.96it/s]
 66%|██████▌   | 217/331 [00:11<00:08, 14.04it/s]
 66%|██████▌   | 219/331 [00:11<00:07, 14.06it/s]
 67%|██████▋   | 221/331 [00:11<00:07, 14.10it/s]
 67%|██████▋   | 223/331 [00:11<00:07, 14.07it/s]
 68%|██████▊   | 225/331 [00:12<00:07, 14.05it/s]
 69%|██████▊   | 227/331 [00:12<00:07, 13.75it/s]
 69%|██████▉   | 229/331 [00:12<00:07, 13.72it/s]
 70%|██████▉   | 231/331 [00:12<00:07, 13.60it/s]
 70%|███████   | 233/331 [00:12<00:07, 13.37it/s]
 71%|███████   | 235/331 [00:12<00:07, 13.37it/s]
 72%|███████▏  | 237/331 [00:12<00:07, 13.37it/s]
 72%|███████▏  | 239/331 [00:13<00:06, 13.42it/s]
 73%|███████▎  | 241/331 [00:13<00:06, 13.36it/s]
 73%|███████▎  | 243/331 [00:13<00:06, 13.47it/s]
 74%|███████▍  | 245/331 [00:13<00:06, 13.36it/s]
 75%|███████▍  | 247/331 [00:13<00:06, 13.43it/s]
 75%|███████▌  | 249/331 [00:13<00:06, 13.22it/s]
 76%|███████▌  | 251/331 [00:14<00:06, 13.16it/s]
 76%|███████▋  | 253/331 [00:14<00:05, 13.08it/s]
 77%|███████▋  | 255/331 [00:14<00:05, 13.16it/s]
 78%|███████▊  | 257/331 [00:14<00:05, 13.16it/s]
 78%|███████▊  | 259/331 [00:14<00:05, 13.11it/s]
 79%|███████▉  | 261/331 [00:14<00:05, 12.83it/s]
 79%|███████▉  | 263/331 [00:14<00:05, 12.99it/s]
 80%|████████  | 265/331 [00:15<00:05, 12.95it/s]
 81%|████████  | 267/331 [00:15<00:04, 13.01it/s]
 81%|████████▏ | 269/331 [00:15<00:04, 13.00it/s]
 82%|████████▏ | 271/331 [00:15<00:04, 13.16it/s]
 82%|████████▏ | 273/331 [00:15<00:04, 13.17it/s]
 83%|████████▎ | 275/331 [00:15<00:04, 13.30it/s]
 84%|████████▎ | 277/331 [00:16<00:04, 13.30it/s]
 84%|████████▍ | 279/331 [00:16<00:03, 13.49it/s]
 85%|████████▍ | 281/331 [00:16<00:03, 13.36it/s]
 85%|████████▌ | 283/331 [00:16<00:03, 13.58it/s]
 86%|████████▌ | 285/331 [00:16<00:03, 13.56it/s]
 87%|████████▋ | 287/331 [00:16<00:03, 13.72it/s]
 87%|████████▋ | 289/331 [00:16<00:03, 13.71it/s]
 88%|████████▊ | 291/331 [00:17<00:02, 13.88it/s]
 89%|████████▊ | 293/331 [00:17<00:02, 13.87it/s]
 89%|████████▉ | 295/331 [00:17<00:02, 14.08it/s]
 90%|████████▉ | 297/331 [00:17<00:02, 13.88it/s]
 90%|█████████ | 299/331 [00:17<00:02, 13.93it/s]
 91%|█████████ | 301/331 [00:17<00:02, 13.63it/s]
 92%|█████████▏| 303/331 [00:17<00:02, 13.65it/s]
 92%|█████████▏| 305/331 [00:18<00:01, 13.44it/s]
 93%|█████████▎| 307/331 [00:18<00:01, 13.32it/s]
 93%|█████████▎| 309/331 [00:18<00:01, 13.12it/s]
 94%|█████████▍| 311/331 [00:18<00:01, 13.19it/s]
 95%|█████████▍| 313/331 [00:18<00:01, 13.05it/s]
 95%|█████████▌| 315/331 [00:18<00:01, 13.13it/s]
 96%|█████████▌| 317/331 [00:18<00:01, 12.92it/s]
 96%|█████████▋| 319/331 [00:19<00:00, 12.62it/s]
 97%|█████████▋| 321/331 [00:19<00:00, 12.07it/s]
 98%|█████████▊| 323/331 [00:19<00:00, 11.38it/s]
 98%|█████████▊| 325/331 [00:19<00:00, 10.31it/s]
 99%|█████████▉| 327/331 [00:20<00:00,  9.59it/s]
 99%|█████████▉| 328/331 [00:20<00:00,  9.07it/s]
 99%|█████████▉| 329/331 [00:20<00:00,  8.66it/s]
100%|█████████▉| 330/331 [00:20<00:00,  8.24it/s]
100%|██████████| 331/331 [00:20<00:00,  7.96it/s]
100%|██████████| 331/331 [00:20<00:00, 16.08it/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})

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

Gallery generated by Sphinx-Gallery