LTX Alpha Refine
A code-only companion pipeline for refining moving-hand boundaries in white-background LTX Alpha Gen outputs.
This repository publishes executable refinement code, model provenance, reproducibility tools and scoped runtime research. It contains no newly trained checkpoint, merged LTX weights, or bundled third-party models. There is no hosted inference endpoint or automatic from_pretrained() model in this repository.
Source and development on GitHub · Full usage guide · 中文说明 · Validation
What it does
Coarse video Alpha can lag behind moving fingers, clipping foreground while leaving white spill. The pipeline uses current-frame source RGB and hand locations to refine the affected regions:
- Obtain hand detections, retaining weak detections only when adjacent-frame evidence supports the current frame's own geometry.
- Release coarse trimap labels contradicted by source-image evidence.
- Run local ViTMatte with contrast gating, bounded writeback and white-background color decontamination.
- Conditionally recover white foreground holes using material continuity and model confidence.
- Overlap frame-local CPU work while serializing shared GPU inference.
Adjacent frames do not warp Alpha or substitute interpolated hand boxes. Empty hand regions leave the input unchanged. Output is straight-alpha RGBA and separate Alpha PNGs.
Use locally
Tested on Linux, RTX 5060 Ti 16GB, CUDA/BF16. This command refines existing Alpha frames; LTX generation and decoding are separate.
git clone https://huggingface.co/hugyouhugyou/ltx-alpha-refine
cd ltx-alpha-refine
python -m pip install -e '.[detect]'
Obtain the refinement models from their original repositories and follow their respective terms:
hf download hustvl/vitmatte-small-composition-1k \
model.safetensors config.json preprocessor_config.json --local-dir models/vitmatte
hf download deepghs/anime_hand_detection \
hand_detect_v1.0_s/model.onnx hand_detect_v1.0_s/threshold.json \
hand_detect_v1.0_s/labels.json --local-dir models/hand-detector
python tools/verify_models.py --vitmatte-dir models/vitmatte \
--detector-dir models/hand-detector/hand_detect_v1.0_s
ltx-alpha-refine \
--source-frames inputs/rgb --alpha-frames inputs/alpha \
--vitmatte-dir models/vitmatte \
--detector-dir models/hand-detector/hand_detect_v1.0_s \
--output outputs/example
Inputs must have matching dimensions and contiguous frame names (00000.png, 00001.png, ...). Alpha should be 8-bit single-channel PNG. Use --raw-rgb-alpha for raw RGB matte frames from LTX, and --allow-alpha-tail only for explicit trailing model padding. No implicit resizing or frame-rate conversion occurs. An explicit --detections boxes.json interface allows an alternative detector. See USAGE for its schema and a separate detector environment.
Evaluation and timing scope
- Regression set: 13 anonymized characters, 15 clips, 1,860 frames. These data informed development; they are not an unseen generalization benchmark.
- Extracted refinement code reproduced the accepted reference Alpha and RGBA pixels exactly across that regression set. Equality with a reference implementation is not ground-truth matting accuracy.
- The independent CLI reproduced a complete 124-frame sequence exactly. Ten synthetic contract tests cover alignment, locality, detection geometry and lossless output.
- The complete optimized LTX integration measured approximately 59.7 seconds on one repeated 124-frame sample at 768×576 / 24fps. That includes phase loading, detection, denoising, decoding, refinement and completed PNG writes; it excludes input preparation, startup, queueing, video encoding and first-use weight-cache construction.
- The 59.7-second figure is not the runtime of this standalone refiner. The complete acceleration integration is not packaged as an executable model here. The persistent-weight-cache experiment and its integration constraints are documented separately.
Benchmark attribution and ablations · Upstream loader proposal · Experimental cache reference
Limitations
The evaluated scope is near-white-background stylized character video, predominantly 768×576, 24fps and 124 frames. White clothing or hair, transparent materials, low contrast and fast occlusion remain difficult. No claim is made of perfect boundaries, performance on arbitrary backgrounds, real-time causal streaming, a smaller LTX architecture, or universal numerical identity across hardware. Model weights and training procedures were not changed by this contribution.
Private character media are not redistributed. Evaluation records use anonymous identifiers. Obtain permission for any media used with the pipeline.
Attribution and licensing
The code in this repository is Apache-2.0. That does not relicense the external models, which users obtain independently:
- Lightricks LTX2.5 and Alpha Gen.
- lvladikov's two-step distillation adapter. The reduction to two denoising steps is the adapter author's contribution.
- ViTMatte-S.
- DeepGHS anime hand detection.
This is a community companion implementation, not an official Lightricks release. It combines established methods with a bounded refinement workflow and measured engineering changes. See THIRD_PARTY for attribution and separate model terms. AI assistance was used in implementation, experiments and documentation.
中文说明
这是面向白底人物视频的 LTX Alpha 修复代码与研究记录,不含新训练权重。手部检测与原图证据用于局部修正蒙版、减少白边,并对低对比区域采用保守回写。约 59.7 秒是完整集成流程的历史实测值,不是本仓库独立后处理命令的运行时间。所有角色和素材均采用匿名标识,详细用法见中文简介和使用指南。