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<01:04,  5.15it/s]
  2%|▏         | 5/331 [00:00<00:17, 19.08it/s]
  3%|▎         | 10/331 [00:00<00:11, 29.12it/s]
  5%|▍         | 15/331 [00:00<00:08, 35.13it/s]
  6%|▌         | 20/331 [00:00<00:08, 38.27it/s]
  8%|▊         | 25/331 [00:00<00:07, 39.52it/s]
  9%|▉         | 30/331 [00:00<00:07, 39.17it/s]
 11%|█         | 35/331 [00:01<00:08, 34.14it/s]
 12%|█▏        | 39/331 [00:01<00:09, 31.29it/s]
 13%|█▎        | 43/331 [00:01<00:09, 28.89it/s]
 14%|█▍        | 47/331 [00:01<00:10, 27.36it/s]
 15%|█▌        | 50/331 [00:01<00:10, 26.47it/s]
 16%|█▌        | 53/331 [00:01<00:10, 26.01it/s]
 17%|█▋        | 56/331 [00:01<00:10, 25.61it/s]
 18%|█▊        | 59/331 [00:02<00:10, 25.22it/s]
 19%|█▊        | 62/331 [00:02<00:10, 25.09it/s]
 20%|█▉        | 65/331 [00:02<00:10, 24.83it/s]
 21%|██        | 68/331 [00:02<00:10, 24.33it/s]
 21%|██▏       | 71/331 [00:02<00:10, 24.55it/s]
 22%|██▏       | 74/331 [00:02<00:10, 24.52it/s]
 23%|██▎       | 77/331 [00:02<00:10, 24.21it/s]
 24%|██▍       | 80/331 [00:02<00:10, 24.57it/s]
 25%|██▌       | 83/331 [00:03<00:09, 24.86it/s]
 26%|██▌       | 86/331 [00:03<00:09, 24.52it/s]
 27%|██▋       | 89/331 [00:03<00:09, 24.64it/s]
 28%|██▊       | 92/331 [00:03<00:09, 25.81it/s]
 29%|██▉       | 96/331 [00:03<00:08, 27.22it/s]
 30%|██▉       | 99/331 [00:03<00:08, 27.83it/s]
 31%|███       | 102/331 [00:03<00:08, 28.19it/s]
 32%|███▏      | 105/331 [00:03<00:07, 28.35it/s]
 33%|███▎      | 109/331 [00:03<00:07, 28.96it/s]
 34%|███▍      | 113/331 [00:04<00:07, 29.46it/s]
 35%|███▌      | 117/331 [00:04<00:07, 29.82it/s]
 36%|███▋      | 120/331 [00:04<00:07, 29.79it/s]
 37%|███▋      | 123/331 [00:04<00:07, 28.92it/s]
 38%|███▊      | 126/331 [00:04<00:07, 29.17it/s]
 39%|███▉      | 129/331 [00:04<00:06, 29.35it/s]
 40%|████      | 133/331 [00:04<00:06, 29.36it/s]
 41%|████      | 136/331 [00:04<00:06, 29.40it/s]
 42%|████▏     | 139/331 [00:04<00:06, 29.46it/s]
 43%|████▎     | 142/331 [00:05<00:06, 29.46it/s]
 44%|████▍     | 145/331 [00:05<00:06, 29.38it/s]
 45%|████▍     | 148/331 [00:05<00:06, 29.32it/s]
 46%|████▌     | 151/331 [00:05<00:06, 29.21it/s]
 47%|████▋     | 155/331 [00:05<00:05, 31.49it/s]
 48%|████▊     | 159/331 [00:05<00:05, 32.89it/s]
 49%|████▉     | 163/331 [00:05<00:05, 33.23it/s]
 50%|█████     | 167/331 [00:05<00:06, 24.07it/s]
 51%|█████▏    | 170/331 [00:06<00:09, 16.60it/s]
 52%|█████▏    | 173/331 [00:06<00:11, 13.83it/s]
 53%|█████▎    | 175/331 [00:06<00:11, 13.06it/s]
 53%|█████▎    | 177/331 [00:07<00:12, 12.77it/s]
 54%|█████▍    | 179/331 [00:07<00:11, 12.70it/s]
 55%|█████▍    | 181/331 [00:07<00:11, 12.66it/s]
 55%|█████▌    | 183/331 [00:07<00:11, 12.89it/s]
 56%|█████▌    | 185/331 [00:07<00:11, 13.16it/s]
 56%|█████▋    | 187/331 [00:07<00:10, 13.77it/s]
 57%|█████▋    | 189/331 [00:07<00:09, 14.33it/s]
 58%|█████▊    | 191/331 [00:07<00:09, 15.05it/s]
 58%|█████▊    | 193/331 [00:08<00:08, 15.77it/s]
 59%|█████▉    | 195/331 [00:08<00:08, 16.34it/s]
 60%|█████▉    | 197/331 [00:08<00:07, 17.03it/s]
 60%|██████    | 199/331 [00:08<00:07, 17.45it/s]
 61%|██████    | 201/331 [00:08<00:07, 17.73it/s]
 61%|██████▏   | 203/331 [00:08<00:07, 17.91it/s]
 62%|██████▏   | 205/331 [00:08<00:07, 17.98it/s]
 63%|██████▎   | 207/331 [00:08<00:06, 17.96it/s]
 63%|██████▎   | 209/331 [00:08<00:07, 17.32it/s]
 64%|██████▎   | 211/331 [00:09<00:06, 17.40it/s]
 64%|██████▍   | 213/331 [00:09<00:06, 17.16it/s]
 65%|██████▍   | 215/331 [00:09<00:06, 16.79it/s]
 66%|██████▌   | 217/331 [00:09<00:07, 15.95it/s]
 66%|██████▌   | 219/331 [00:09<00:07, 15.27it/s]
 67%|██████▋   | 221/331 [00:09<00:07, 15.21it/s]
 67%|██████▋   | 223/331 [00:09<00:07, 15.28it/s]
 68%|██████▊   | 225/331 [00:10<00:06, 15.36it/s]
 69%|██████▊   | 227/331 [00:10<00:06, 15.38it/s]
 69%|██████▉   | 229/331 [00:10<00:06, 15.54it/s]
 70%|██████▉   | 231/331 [00:10<00:06, 15.70it/s]
 70%|███████   | 233/331 [00:10<00:06, 15.62it/s]
 71%|███████   | 235/331 [00:10<00:06, 15.84it/s]
 72%|███████▏  | 237/331 [00:10<00:05, 15.86it/s]
 72%|███████▏  | 239/331 [00:10<00:05, 16.10it/s]
 73%|███████▎  | 241/331 [00:11<00:05, 16.10it/s]
 73%|███████▎  | 243/331 [00:11<00:05, 16.28it/s]
 74%|███████▍  | 245/331 [00:11<00:05, 16.16it/s]
 75%|███████▍  | 247/331 [00:11<00:05, 15.97it/s]
 75%|███████▌  | 249/331 [00:11<00:05, 15.70it/s]
 76%|███████▌  | 251/331 [00:11<00:05, 15.80it/s]
 76%|███████▋  | 253/331 [00:11<00:04, 15.62it/s]
 77%|███████▋  | 255/331 [00:11<00:04, 15.41it/s]
 78%|███████▊  | 257/331 [00:12<00:04, 15.34it/s]
 78%|███████▊  | 259/331 [00:12<00:04, 15.21it/s]
 79%|███████▉  | 261/331 [00:12<00:04, 15.18it/s]
 79%|███████▉  | 263/331 [00:12<00:04, 15.03it/s]
 80%|████████  | 265/331 [00:12<00:04, 15.08it/s]
 81%|████████  | 267/331 [00:12<00:04, 15.13it/s]
 81%|████████▏ | 269/331 [00:12<00:04, 15.07it/s]
 82%|████████▏ | 271/331 [00:12<00:04, 14.94it/s]
 82%|████████▏ | 273/331 [00:13<00:03, 14.81it/s]
 83%|████████▎ | 275/331 [00:13<00:03, 14.77it/s]
 84%|████████▎ | 277/331 [00:13<00:03, 14.74it/s]
 84%|████████▍ | 279/331 [00:13<00:03, 14.71it/s]
 85%|████████▍ | 281/331 [00:13<00:03, 14.65it/s]
 85%|████████▌ | 283/331 [00:13<00:03, 14.71it/s]
 86%|████████▌ | 285/331 [00:13<00:03, 14.75it/s]
 87%|████████▋ | 287/331 [00:14<00:02, 14.98it/s]
 87%|████████▋ | 289/331 [00:14<00:02, 14.94it/s]
 88%|████████▊ | 291/331 [00:14<00:02, 14.85it/s]
 89%|████████▊ | 293/331 [00:14<00:02, 14.65it/s]
 89%|████████▉ | 295/331 [00:14<00:02, 14.29it/s]
 90%|████████▉ | 297/331 [00:14<00:02, 14.30it/s]
 90%|█████████ | 299/331 [00:14<00:02, 14.60it/s]
 91%|█████████ | 301/331 [00:15<00:02, 14.45it/s]
 92%|█████████▏| 303/331 [00:15<00:01, 14.75it/s]
 92%|█████████▏| 305/331 [00:15<00:01, 14.70it/s]
 93%|█████████▎| 307/331 [00:15<00:01, 14.78it/s]
 93%|█████████▎| 309/331 [00:15<00:01, 14.72it/s]
 94%|█████████▍| 311/331 [00:15<00:01, 14.65it/s]
 95%|█████████▍| 313/331 [00:15<00:01, 14.52it/s]
 95%|█████████▌| 315/331 [00:15<00:01, 14.60it/s]
 96%|█████████▌| 317/331 [00:16<00:00, 14.30it/s]
 96%|█████████▋| 319/331 [00:16<00:00, 13.89it/s]
 97%|█████████▋| 321/331 [00:16<00:00, 13.07it/s]
 98%|█████████▊| 323/331 [00:16<00:00, 12.23it/s]
 98%|█████████▊| 325/331 [00:16<00:00, 11.32it/s]
 99%|█████████▉| 327/331 [00:17<00:00, 10.55it/s]
 99%|█████████▉| 329/331 [00:17<00:00,  9.81it/s]
100%|██████████| 331/331 [00:17<00:00,  9.34it/s]
100%|██████████| 331/331 [00:17<00:00, 18.85it/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 20.301 seconds)

Gallery generated by Sphinx-Gallery