Skip to content

Instantly share code, notes, and snippets.

@JupyterJones
Created February 12, 2026 06:57
Show Gist options
  • Select an option

  • Save JupyterJones/6dc100be5e7c35bfb59b2d6048935434 to your computer and use it in GitHub Desktop.

Select an option

Save JupyterJones/6dc100be5e7c35bfb59b2d6048935434 to your computer and use it in GitHub Desktop.
Super zoom images for video creation
import os
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from scipy.signal import convolve2d
# ------------------------
# Setup
# ------------------------
os.makedirs("framez", exist_ok=True)
# Load original image as float32
img = np.float32(
PIL.Image.open("/home/jack/Desktop/Images/shakki-aug14/AI_Image_Generation-Shakker.AI_files/00039.jpg").convert("RGB")
)
h, w = img.shape[:2]
num_frames = 1500
zoom_per_frame = 0.001 # small zoom increment
# Light sharpening kernel (ultra gentle)
kernel_sharpening = np.array([[-0.05, -0.05, -0.05],
[-0.05, 1.3, -0.05],
[-0.05, -0.05, -0.05]])
# ------------------------
# Ultra-light sharpening function
# ------------------------
def sharpen_frame(frame, kernel=kernel_sharpening):
sharpened = np.zeros_like(frame)
for c in range(3):
sharpened[..., c] = convolve2d(frame[..., c], kernel, mode='same', boundary='symm')
return np.clip(sharpened, 0, 255)
# ------------------------
# Frame generation loop
# ------------------------
for i in range(num_frames):
# Compute zoom factor relative to original
zoom_factor = (1 - zoom_per_frame) ** i
# Affine transform from original image (prevents cumulative blur)
frame = nd.affine_transform(
img,
[zoom_factor, zoom_factor, 1],
[h * (1 - zoom_factor) / 2, w * (1 - zoom_factor) / 2, 0],
order=3 # cubic interpolation keeps edges sharp
)
# Optional: sharpen every 10 frames
if i % 10 == 0:
frame = sharpen_frame(frame)
# Save frame
PIL.Image.fromarray(np.uint8(frame)).save(f"framez/{i:05d}.jpg")
@JupyterJones
Copy link
Author

to create a video from the images:
ffmpeg -hide_banner -framerate 3 -i %05d.jpg -c:v libx265 -r 30 -pix_fmt yuv420p -y slow-3per-sec-jpgs.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment