Nodes/Loop Strip/Loop Strip — Center Subject
ComfyUI Node

Loop Strip — Center Subject

Stop the character drifting in your loop

By serhiiyashyn-sf·Created 5 months ago·Updated 4 months ago· 0
Loop Strip — Center Subject
  • frames
  • masks
  • centered_frames
output_width512
output_height512
fill_percent0.55
threshold0.12

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:

  1. 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.
  2. 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.
  3. 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.
  4. It scales the entire frame so the subject's height fills fill_percent of 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.

CategoryLoopStrip

Inputs (6)

NameTypeDefaultDescription
framesIMAGE
output_widthINT51264–4096Output frame width
output_heightINT51264–4096Output frame height
fill_percentFLOAT0.550.3–0.95How much of the canvas the character fills (0.6 = 60%, the blue box)
thresholdFLOAT0.120.01–0.5How different a pixel must be from the background to count as subject
masksoptMASKOptional masks from segmentation node. If not provided, auto-detects via background color.

Outputs (1)

NameTypeDescription
centered_framesIMAGE