import glob
from PIL import Image
import glob
# filepaths
fp_in = "images/keras_detection/clone_p*.jpg"
fp_out = "images/keras_detection/sliding_window_sw.gif"

# https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif
img, *imgs = [Image.open(f) for f in sorted(glob.glob(fp_in))]
img.save(fp=fp_out, format='GIF', append_images=imgs,
         save_all=True, duration=2000, loop=0)
fp_in = "images/keras_detection/roiOrig_p*.jpg"
fp_out = "images/keras_detection/sliding_window_rois.gif"

# https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif
img, *imgs = [Image.open(f) for f in sorted(glob.glob(fp_in))]
img.save(fp=fp_out, format='GIF', append_images=imgs,
         save_all=True, duration=2000, loop=0)

Sliding window and ROIs for an image with three hierachical pyramids