Communitygithub.com

person-matte-video

Cuts a real person out of video footage and composites them over a new or repainted background with a stable, clean alpha matte (background removal, rotoscoping, video segmentation without a green screen). Use when someone wants themselves or another person placed into a painting, an illustration or a new background, or when an existing composite has a jumping or flickering matte, cut-off or "eaten" limbs, a background showing through a limb, haloes or old-background fringes, or a person who looks softer than in the original. Local Python pipeline (BiRefNet via rembg, OpenCV optical flow, temporal stabilisation, keyframed roto, compositing, QA sheets, encoding for phones). Not for still photos only, generating new footage of a person, or changing how a person looks.

Was ist person-matte-video?

person-matte-video is a Claude Code agent skill that cuts a real person out of video footage and composites them over a new or repainted background with a stable, clean alpha matte (background removal, rotoscoping, video segmentation without a green screen). Use when someone wants themselves or another person placed into a painting, an illustration or a new background, or when an existing composite has a jumping or flickering matte, cut-off or "eaten" limbs, a background showing through a limb, haloes or old-background fringes, or a person who looks softer than in the original. Local Python pipeline (BiRefNet via rembg, OpenCV optical flow, temporal stabilisation, keyframed roto, compositing, QA sheets, encoding for phones). Not for still photos only, generating new footage of a person, or changing how a person looks.

Funktioniert mit✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/barbaramania/person-matte-video/tree/HEAD/skills/person-matte-video

In Ihrer bevorzugten KI fragen

Öffnet einen neuen Chat, in dem dieser Agent-Skill bereits geladen ist.

Dokumentation

Person matte for video

A neural matte on its own boils, loses limbs in shadow and eats thin parts. This skill wraps it in a pipeline that fixes those failures one by one, plus a review loop with the person who owns the footage.

Run every script as python <skill-dir>/scripts/NAME.py ... (<skill-dir> is this skill's folder; in Claude Code ${CLAUDE_SKILL_DIR}) from the folder that holds project.json (paths inside the config are relative to it; paths on the command line are relative to the current folder). Scripts print their usage when run without arguments (-h for the full help). One JSON project file drives everything: read config first.

Before you start

  • Consent and privacy. The footage shows a real person. Everything here runs locally. Send their frames to an external model or service (an image generator, a cloud matting API) only after the owner names the service and agrees. Never upload, publish or share their footage or stills yourself. Never alter or "improve" their face or body shape; colour grading the whole person is fine when asked.
  • Install: pip install -r <skill-dir>/requirements.txt (Python 3.12+, ideally in a virtual environment).
  • Self-check: python <skill-dir>/tests/test_pipeline.py (synthetic clip, no real footage; --model also runs BiRefNet).
  • Clean plate (background without the person, same framing) - needed for the shadow veto, hole fill and the cast shadow. Options: a frame before the person enters or after they leave; a per-pixel temporal median over frames where the person moved away; a separate empty shot. Filling the person out with a generative model counts as sending their frames out: only with the owner's consent.
  • Work on copies. Keep every rendered version in its own folder (work/out_v1, work/out_v2, ...) and never delete earlier versions: the comparison tools need them, and an earlier version may turn out to be the preferred one.
  • Ask which output files the owner needs and produce only those.

Pipeline

  1. Frames. extract_frames.py video.mp4 frames/ - lossless PNGs; it prints the source fps for the config. If the shot must be levelled, cropped or reframed, do it once at this point, so camera frames, mattes and output share one geometry.
  2. Scenes. Split the timeline into scenes in the config ([start, end), one background each, "keep" for the untouched camera). Mattes are never interpolated or averaged across a scene boundary.
  3. Keys. matte_keys.py project.json - BiRefNet every key_stride frames (3 is a good start), every frame inside matte.per_frame, and zoomed re-runs of small parts in matte.zoom_boxes.
  4. In-betweens. matte_interp.py project.json - optical-flow warp of the neighbouring keys. Frames where the two keys disagree (fast or thin motion -> doubled, ghosted limbs) go to work/interp_suggest.json: add those ranges to matte.per_frame and run matte_keys.py project.json a b and matte_interp.py project.json a b again for them. If most of a scene is flagged, lower key_stride instead. After changing any matte setting, move the old files of that range out of work/keys first: matte_interp uses every key file it finds.
  5. Refine (optional). matte_refine.py project.json - gate to an existing approved cut-out (refine.reference), remove the semi-transparent cast shadow against the clean plate (refine.shadow_veto; a shadow matted solidly needs a roto sub shape), fill small holes. Skin in shade is darker than the plate too: see troubleshooting before enabling the shadow veto.
  6. Stabilise. matte_stabilize.py project.json - long temporal average where nothing moves, none where it does.
  7. Roto (only where needed). Shapes in roto.json for parts no matte gets right (schema in roto.py and config); read vertices off sheets.py grid, preview with roto.py project.json FRAME out.png.
  8. Composite. composite.py project.json - edge decontamination, optional camera detail over a graded version (composite.detail_from), cast shadow, shade regions, fringe regions. Roto and fringe regions act here, so work/matte shows the alpha before them; preview roto with roto.py.
  9. Encode. encode.py "work/out/%05d.png" NAME --project project.json --profiles social -> NAME_social.mp4 (add master only if wanted; --audio original.mp4 puts the original sound on the social file, padded or cut to the video length).

After changing any pass, re-run every later pass for the affected frames (keys -> interp -> refine -> stabilise -> composite). Render into work/out, then copy the frames to work/out_vN before the next change.

Review loop with the owner

Owners often review on a phone and send screenshots of what looks wrong. Work like this:

  1. Locate, don't guess. locate_screenshot.py shot.png "work/out_vN/%05d.png" FIRST LAST gives frame and box (score > 0.9); refine with --step 1 around the hit. Then compare camera | previous | new crops with sheets.py compare.
  2. Diagnose before fixing. Look at the matte value at the bad pixels (work/matte), the camera pixels and the background layer separately: is the wrong colour coming from the person layer (matte or a contaminated edge) or from the background? Many "the background is wrong" reports are a contaminated edge of the person layer. troubleshooting maps symptoms to causes.
  3. Measure. Put a box per flagged place into regions.json and run jitter.py on the old and new version; report the numbers per place. A real movement keeps a high count; a fixed boil drops toward 0.
  4. Sharpness. Whenever the person's pixels come from another version, compare a head crop with the camera (sheets.py sharp); a resampled or compressed grade can lose a noticeable share of the detail.
  5. Independent review before sending. Have 2-5 reviewers (subagents or a workflow) look at the QA sheets with different lenses and try to refute the fix; verify every non-minor finding before acting. See review.
  6. After two misses on the same spot, stop guessing. Render 2-3 options on one frame next to the original (sheets.py compare) and let the owner choose. The original footage is the target for shape and light; do not "improve" it (for example by relighting a part that is truly in shadow).
  7. Report per item: what changed, the numbers, what is not verified. Send each video file separately.

Files

  • config - every config key, defaults, roto schema; read before writing project.json
  • troubleshooting - symptom -> cause -> fix; read when a review comes back
  • review - QA sheets, review lenses, prompts for review agents; read before sending a version
  • scripts/ - the pipeline; tests/ - synthetic clip generator and end-to-end test

Verwandte Skills