Loop Strip — Center Subject
Stop the character drifting in your loop
- frames
- masks
- centered_frames
The walk cycle is found. Now the character is shuffling around inside the frame, and if you assemble a sprite strip the way it is, every sprite sits at a slightly different position - the animation looks like the character is vibrating on a train. This node fixes that by re-centering the subject on a stable canvas across every frame of a batch.
You reach for it after Loop Strip - Find Best Cycle and before Loop Strip - Assemble Sprite Strip: a clean, uniform, centered batch is exactly what the assembler wants.
How it works
It's the batch-centric sibling of the pack's single-image centering, and the approach is noticeably careful about consistency. From the source:
- It samples 8px strips from all four edges of all frames and takes the median - that's the estimated background color. The median is robust to the character occasionally overlapping an edge.
- If you don't supply masks, it differences each frame against that background and Otsu-thresholds to find the subject, closing small holes with a morphology pass. If you do supply masks (say from a segmentation node), those are used instead.
- Crucially, it computes a union bounding box across every frame - the character's full extent over the whole clip - and the median of all mask pixels as the center point. Union + median is what makes the framing stable instead of jittering frame-to-frame, which is the whole point of this node.
- It scales the entire frame so the subject's height fills
fill_percentof the output (also checking width fits), then pastes into an output canvas colored with the detected background.
The centered_frames output is a re-framed, uniformly scaled batch, ready for assembly.
Inputs that matter
- output_width / output_height - your canvas, default 512×512. Match these to what your final sprites should be.
- fill_percent (default 0.55) - how much of the canvas the character occupies. 0.55 is a comfortable 55%; push toward 0.6–0.7 for a tighter crop.
- threshold (default 0.12) - how different a pixel must be from the background to count as subject. Only used when you don't pass masks. Lower it if the character is partially blending into the background.
- masks (optional) - drop in masks from a segmentation node for cleaner edges than auto-detection gives you, especially on hair or semi-transparent bits. The pack's own docs point at BiRefNet/RMBG for that job.
Install
Same pack, same story. ComfyUI Manager → search "Loop Strip" → install. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/serhiiyashyn-sf/comfyui-loopstrip
cd comfyui-loopstrip
pip install -r requirements.txt
Restart after. Dependencies (opencv-python, numpy, torch, scipy, requests) are already present in a typical ComfyUI setup, and no model downloads are required.
The trap
This node assumes a clean, fairly constant background - it literally estimates one background color from the frame edges. If your background is animated, gradient, or full of moving junk, the background guess is wrong and your "subject" becomes a noisy blob. Two workarounds: feed it proper masks from a segmentation model (the reliable path for anything tricky), or preprocess to a flat backdrop before loading the video. And if your subject moves a lot horizontally, the union bounding box grows to cover every position - that's a correct, stable framing, just possibly with more empty space than you wanted. That's the honest trade-off for zero jitter.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| frames | IMAGE | — | |
| output_width | INT | 51264–4096 | Output frame width |
| output_height | INT | 51264–4096 | Output frame height |
| fill_percent | FLOAT | 0.550.3–0.95 | How much of the canvas the character fills (0.6 = 60%, the blue box) |
| threshold | FLOAT | 0.120.01–0.5 | How different a pixel must be from the background to count as subject |
| masksopt | MASK | Optional masks from segmentation node. If not provided, auto-detects via background color. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| centered_frames | IMAGE | — |