Skip to content

Instantly share code, notes, and snippets.

@robbibt
Created April 2, 2019 02:36
Show Gist options
  • Select an option

  • Save robbibt/18c782fcac6a04014ac30ab8fac36f17 to your computer and use it in GitHub Desktop.

Select an option

Save robbibt/18c782fcac6a04014ac30ab8fac36f17 to your computer and use it in GitHub Desktop.
Take two images and export frames fading between both images with a smooth transition
import imageio
import numpy as np
from_array = imageio.imread('Visualisation/pilbara/pilbara_before.png')
to_array = imageio.imread('Visualisation/pilbara/pilbara_after.png')
stacked_from_to = np.stack([to_array, from_array], axis=3)
weights = [0.2, 0.4, 0.6, 0.8, 1.0, 0.8, 0.6, 0.4, 0.2, 0]
milliseconds = [50, 50, 50, 50, 3500, 50, 50, 50, 50, 3500]
for i, weight in enumerate(weights):
ave_from_to = np.average(stacked_from_to, axis=3, weights=np.array([weight, 1.0 - weight]))
imageio.imwrite(f'Visualisation/pilbara/output_{i}_({milliseconds[i]}ms).png', ave_from_to.astype(np.uint8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment