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 (1089, 661) to (1104, 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).

  0%|          | 1/331 [00:00<00:45,  7.30it/s]
  2%|▏         | 7/331 [00:00<00:09, 32.84it/s]
  4%|▍         | 14/331 [00:00<00:06, 47.32it/s]
  6%|▋         | 21/331 [00:00<00:05, 54.24it/s]
  8%|▊         | 27/331 [00:00<00:05, 56.04it/s]
 10%|▉         | 33/331 [00:00<00:05, 52.40it/s]
 12%|█▏        | 39/331 [00:00<00:06, 45.55it/s]
 13%|█▎        | 44/331 [00:00<00:06, 41.66it/s]
 15%|█▍        | 49/331 [00:01<00:07, 39.60it/s]
 16%|█▋        | 54/331 [00:01<00:07, 38.64it/s]
 18%|█▊        | 58/331 [00:01<00:07, 37.30it/s]
 19%|█▊        | 62/331 [00:01<00:07, 36.35it/s]
 20%|█▉        | 66/331 [00:01<00:07, 36.36it/s]
 21%|██        | 70/331 [00:01<00:07, 36.10it/s]
 22%|██▏       | 74/331 [00:01<00:06, 36.81it/s]
 24%|██▎       | 78/331 [00:01<00:07, 36.01it/s]
 25%|██▍       | 82/331 [00:02<00:07, 35.30it/s]
 26%|██▌       | 86/331 [00:02<00:06, 35.51it/s]
 27%|██▋       | 90/331 [00:02<00:06, 35.79it/s]
 29%|██▊       | 95/331 [00:02<00:06, 37.96it/s]
 30%|███       | 100/331 [00:02<00:05, 39.80it/s]
 32%|███▏      | 105/331 [00:02<00:05, 39.56it/s]
 33%|███▎      | 110/331 [00:02<00:05, 40.51it/s]
 35%|███▍      | 115/331 [00:02<00:05, 41.77it/s]
 36%|███▋      | 120/331 [00:02<00:04, 42.69it/s]
 38%|███▊      | 125/331 [00:03<00:04, 42.73it/s]
 39%|███▉      | 130/331 [00:03<00:04, 43.09it/s]
 41%|████      | 135/331 [00:03<00:04, 43.58it/s]
 42%|████▏     | 140/331 [00:03<00:04, 43.40it/s]
 44%|████▍     | 145/331 [00:03<00:04, 43.31it/s]
 45%|████▌     | 150/331 [00:03<00:04, 42.67it/s]
 47%|████▋     | 156/331 [00:03<00:03, 46.50it/s]
 49%|████▉     | 162/331 [00:03<00:03, 49.40it/s]
 50%|█████     | 167/331 [00:04<00:04, 39.07it/s]
 52%|█████▏    | 172/331 [00:04<00:06, 25.58it/s]
 53%|█████▎    | 176/331 [00:04<00:06, 22.40it/s]
 54%|█████▍    | 179/331 [00:04<00:07, 21.29it/s]
 55%|█████▍    | 182/331 [00:05<00:07, 20.94it/s]
 56%|█████▌    | 185/331 [00:05<00:07, 20.51it/s]
 57%|█████▋    | 188/331 [00:05<00:06, 20.84it/s]
 58%|█████▊    | 191/331 [00:05<00:06, 21.38it/s]
 59%|█████▊    | 194/331 [00:05<00:06, 22.19it/s]
 60%|█████▉    | 197/331 [00:05<00:05, 22.97it/s]
 60%|██████    | 200/331 [00:05<00:05, 23.37it/s]
 61%|██████▏   | 203/331 [00:05<00:05, 23.66it/s]
 62%|██████▏   | 206/331 [00:06<00:05, 24.04it/s]
 63%|██████▎   | 209/331 [00:06<00:05, 24.06it/s]
 64%|██████▍   | 212/331 [00:06<00:04, 24.39it/s]
 65%|██████▍   | 215/331 [00:06<00:04, 23.91it/s]
 66%|██████▌   | 218/331 [00:06<00:04, 22.94it/s]
 67%|██████▋   | 221/331 [00:06<00:04, 22.25it/s]
 68%|██████▊   | 224/331 [00:06<00:05, 20.96it/s]
 69%|██████▊   | 227/331 [00:07<00:04, 21.44it/s]
 69%|██████▉   | 230/331 [00:07<00:04, 21.92it/s]
 70%|███████   | 233/331 [00:07<00:04, 22.39it/s]
 71%|███████▏  | 236/331 [00:07<00:04, 23.01it/s]
 72%|███████▏  | 239/331 [00:07<00:03, 23.02it/s]
 73%|███████▎  | 242/331 [00:07<00:03, 23.34it/s]
 74%|███████▍  | 245/331 [00:07<00:03, 23.37it/s]
 75%|███████▍  | 248/331 [00:07<00:03, 23.58it/s]
 76%|███████▌  | 251/331 [00:08<00:03, 23.47it/s]
 77%|███████▋  | 254/331 [00:08<00:03, 23.48it/s]
 78%|███████▊  | 257/331 [00:08<00:03, 23.54it/s]
 79%|███████▊  | 260/331 [00:08<00:03, 23.36it/s]
 79%|███████▉  | 263/331 [00:08<00:02, 22.91it/s]
 80%|████████  | 266/331 [00:08<00:02, 22.88it/s]
 81%|████████▏ | 269/331 [00:08<00:02, 22.83it/s]
 82%|████████▏ | 272/331 [00:08<00:02, 22.85it/s]
 83%|████████▎ | 275/331 [00:09<00:02, 22.45it/s]
 84%|████████▍ | 278/331 [00:09<00:02, 22.27it/s]
 85%|████████▍ | 281/331 [00:09<00:02, 22.38it/s]
 86%|████████▌ | 284/331 [00:09<00:02, 22.60it/s]
 87%|████████▋ | 287/331 [00:09<00:01, 22.87it/s]
 88%|████████▊ | 290/331 [00:09<00:01, 22.90it/s]
 89%|████████▊ | 293/331 [00:09<00:01, 23.12it/s]
 89%|████████▉ | 296/331 [00:09<00:01, 23.29it/s]
 90%|█████████ | 299/331 [00:10<00:01, 23.20it/s]
 91%|█████████ | 302/331 [00:10<00:01, 22.52it/s]
 92%|█████████▏| 305/331 [00:10<00:01, 22.01it/s]
 93%|█████████▎| 308/331 [00:10<00:01, 21.78it/s]
 94%|█████████▍| 311/331 [00:10<00:00, 21.56it/s]
 95%|█████████▍| 314/331 [00:10<00:00, 20.99it/s]
 96%|█████████▌| 317/331 [00:11<00:00, 20.64it/s]
 97%|█████████▋| 320/331 [00:11<00:00, 20.13it/s]
 98%|█████████▊| 323/331 [00:11<00:00, 18.71it/s]
 98%|█████████▊| 325/331 [00:11<00:00, 17.48it/s]
 99%|█████████▉| 327/331 [00:11<00:00, 16.49it/s]
 99%|█████████▉| 329/331 [00:11<00:00, 15.26it/s]
100%|██████████| 331/331 [00:11<00:00, 14.24it/s]
100%|██████████| 331/331 [00:11<00:00, 27.69it/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 13.787 seconds)

Gallery generated by Sphinx-Gallery