RENyunfan/composite_image
حول
This repo provide a python script to create a composite image from a video.
التصميم والوسائطما يمكنك فعله
- Live web GUI: scrub the clip, set in and out points, pick frames on a filmstrip. Every slider re-renders the preview in about 10 ms on a GPU.
- 8 composite modes: Outlier, Stroboscope, Light trail, Classic VAR, Lighten, Darken, Long exposure, Clean plate.
- Clean masks: a robust median background, soft thresholds, shadow suppression, a main-subject filter and an exclude brush.
- Styling: a hero frame, ghost desaturation, tint and fade, background grading, contrast, vignette and one-click presets.
النمو المقاس للنجوم
- خلال 24 ساعة
- ٠
- خلال 7 أيام
- ٠
- خلال 15 يومًا
- ٠
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلcomposite_image
Turn a video clip into a single composite image: action sequences, stroboscopic motion studies, light trails, long exposures and clean plates. It comes with an interactive web GUI and a command-line tool. Everything runs on an NVIDIA GPU (CUDA) when one is available, and on the CPU (or Apple MPS) when it is not.

Features
- Live web GUI: scrub the clip, set in and out points, pick frames on a filmstrip. Every slider re-renders the preview in about 10 ms on a GPU.
- 8 composite modes: Outlier, Stroboscope, Light trail, Classic VAR, Lighten, Darken, Long exposure, Clean plate.
- Clean masks: a robust median background, soft thresholds, shadow suppression, a main-subject filter and an exclude brush.
- Styling: a hero frame, ghost desaturation, tint and fade, background grading, contrast, vignette and one-click presets.
- Motion path overlay: tracks the subject or a colour you pick, then draws a smoothed, tapered, glowing path with a comet head.
- Auto-space: picks frames so the subject never overlaps itself.
- Stabilization for handheld footage: ORB + RANSAC alignment, warped on the GPU.
- Full-resolution export to PNG or JPEG. Clips that do not fit in VRAM are streamed from pinned host memory.

Install
Python 3.10+ is required. Install PyTorch for your hardware first, then the remaining dependencies:
python -m venv .venv && source .venv/bin/activate
# NVIDIA GPU (RTX 50xx needs CUDA 12.8 builds or newer)
pip install torch --index-url https://download.pytorch.org/whl/cu128
# CPU only, no NVIDIA GPU (smaller download)
pip install torch --index-url https://download.pytorch.org/whl/cpu
# macOS (Apple silicon uses MPS automatically)
pip install torch
pip install -r requirements.txt
Already have an environment with PyTorch and OpenCV? Build a venv on top of it and add only the web packages:
python -m venv --system-site-packages .venv && .venv/bin/pip install fastapi uvicorn python-multipart
Quick start
python server.py # then open the URL it prints (port 7860) in your browser
python server.py --device cpu # force a device: auto | cuda | mps | cpu (or set COMPOSITE_DEVICE)
- Source: drop a video, or type a local path (try
example_video.mp4). - Clip: press
IandOto set the in and out points. Choose Every N frames, the resolution and stabilization, then click Load frames. - Mode: pick a mode, then tune it. Hold
Mto see the mask,Bthe background, andFthe raw frame. - Frames strip: click to toggle frames and
Shift-click to select a range. Double-click a frame to make it the hero. Auto-space picks non-overlapping frames. - Export renders the full-resolution image.
Without CUDA the GUI loads at ≤1080p by default and the live preview runs at 640 px, so sliders stay responsive.
Modes
| Mode | What it does | Good for |
|---|---|---|
| Outlier | Per pixel, takes the frame that differs most from the median background. A soft threshold keeps static areas clean. | Sports, jumps, drones |
| Stroboscope | Builds a feathered foreground cut-out per frame and layers the cut-outs in time order over the clean plate | Clean sequences with correct occlusion |
| Light trail | Adds up bright or colour-keyed pixels over the selected span, fills the gaps between frames, tone-maps the result (it never clips flat) and screens it over the plate | LEDs, sparklers, car lights, light painting |
| Classic VAR | The original algorithm of this repository, vectorized | Comparison |
| Lighten / Darken | Keeps the brightest or darkest pixel by luma, with its colour | Star trails; dark subjects on bright backgrounds |
| Long exposure | Mean of the frames | Motion blur, silky water |
| Clean plate | Per-pixel median | Removing people and cars |
Why not just the original VAR? It compares a difference of norms against the norm of a difference, uses a mean background that the subject itself pulls off, and has no threshold. As a result, noise and reflections leak into the whole frame. Measured against the clean plate on the example video, Classic VAR changes 1.77% of background pixels by more than 12 levels; Outlier changes 0.16%.

Making it look good

| Group | Controls |
|---|---|
| Subject mask | Threshold, softness, shadow suppression (ignores pixels that are only darker than the background with the same hue), main subject only (largest blob plus its neighbours), denoise, speckle cleanup, grow or shrink, feather, and an exclude brush for screens, trees or passers-by |
| Ghosts & hero | Oldest-frame opacity, ghost desaturation and tint. The hero frame is drawn on top in full colour; in Light trail mode it becomes the background plate. |
| Look | Background brightness and desaturation, S-curve contrast, vignette. Presets: Motion study, Ghost trail, Night neon, Bright scene. |
| Motion path | Track the moving subject or an eyedropper colour key. The path is cleaned of jumps, gap-filled, smoothed and drawn as a spline, with a palette, taper, fade, glow, a dark halo (so it reads on white surfaces), a comet head and an optional behind the subjects mode. It spans the first to last selected frame, so select one movement for one clean line. |
Masks and deviation maps are cached, so look, ghost and path changes never recompute them.
Command line
python composite_gpu.py example_video.mp4 --mode strobe --auto-space 0.03 --subject main \
--hero 100 --ghost-desat 0.7 --bg-dim 0.8 --vignette 0.4 --track subject -o strobe.png
python composite_gpu.py lights.mp4 --mode trail --light-source color --key-color 255,170,40 \
--bg-dim 0.75 --trail-halo 0.3 -o trail.png
python composite_gpu.py --help lists every option. Every GUI slider has a matching flag.
Performance
Example video at 1920×1013 with 71 frames. Times are per render.
| NVIDIA RTX 5090 Laptop (CUDA) | CPU, 12 threads | |
|---|---|---|
| Slider move: Outlier / Stroboscope | ~10 ms | ~80 ms |
| Slider move: Light trail | ~30 ms | ~310 ms |
| Full-res export: Outlier / Stroboscope | ~30 ms | ~1.6 s |
| Full-res export: Light trail | ~110 ms | ~4.4 s |
The first render after a mask change also computes the masks: up to about 0.4 s on the GPU and a few seconds on the CPU.
How it works
- Frames are decoded with OpenCV and stored as uint8 tensors on the compute device, or in pinned host memory when they do not fit. A ≤960 px preview copy (640 px on CPU) drives the live preview.
- All compositing (background estimation, masks, morphology, blurs, warps and blending) runs as PyTorch tensor ops, on CUDA kernels when a GPU is available.
- Path tracking always runs on the preview stack; the path is then rendered at the output resolution.
Files
| File | |
|---|---|
composite_gpu.py |
Engine and command line |
server.py, static/index.html |
Web GUI |
composite_image.py |
The original NumPy script, kept for reference |
example_video.mp4 |
Example clip |
Acknowledgements
The median-background and outlier selection ideas follow chrono-photo. The median background estimation follows LearnOpenCV's background estimation tutorial.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…