| --- |
| license: cc-by-nc-sa-4.0 |
| pipeline_tag: image-segmentation |
| --- |
| |
| # SAM2Matting: Generalized Image and Video Matting |
|
|
| This repository contains the official checkpoints for **SAM2Matting**, a generalized matting framework that decouples high-level tracking from dedicated low-level matting to support robust image and video matting of any open-world targets. |
|
|
| [๐ Paper](https://huggingface.co/papers/2606.27339) | [๐ Project Page](https://henghuiding.com/SAM2Matting/) | [๐ป GitHub](https://github.com/FudanCVL/SAM2Matting) |
|
|
| <p align="center"> |
| <img src="https://raw.githubusercontent.com/FudanCVL/SAM2Matting/main/assets/teaser.png" width="90%" alt="SAM2Matting qualitative results"/> |
| </p> |
|
|
| ## Highlights |
| - **Decoupled design**: Combines a VOS tracker for temporal consistency with ROI Detection & Progressive Matting for fine details. |
| - **Image-only training, video SOTA**: Strong zero-shot video matting performance without requiring expensive video matting datasets. |
| - **Diverse prompts**: Supports masks, points, boxes, and text prompts. |
| - **Open-world generalization**: Robust matting for humans, animals, anime, translucent objects, and rapid-motion scenes. |
|
|
| ## Installation |
|
|
| To run SAM2Matting locally, clone the repository and install the dependencies: |
|
|
| ```bash |
| # clone the repo and enter directory |
| git clone https://github.com/FudanCVL/SAM2Matting.git |
| cd SAM2Matting |
| |
| # create and activate conda environment |
| conda create -n sam2matting python=3.10 -y |
| conda activate sam2matting |
| |
| # install required packages |
| pip install -r requirements.txt |
| ``` |
|
|
| ## Quick Start |
|
|
| The codebase provides separate inference scripts for image and video matting. |
|
|
| To run video matting on a sample with SAM2-based trackers, run: |
|
|
| ```bash |
| python inference_video_sam2.py --save_mp4 |
| ``` |
|
|
| To enable compilation for faster execution (though the first run may be slower): |
|
|
| ```bash |
| python inference_video_sam2.py --save_mp4 --compiled |
| ``` |
|
|
| ## Citation |
|
|
| If you find SAM2Matting useful in your research, please consider citing the work: |
|
|
| ```bibtex |
| @inproceedings{SAM2Matting, |
| title={{SAM2Matting}: Generalized Image and Video Matting}, |
| author={Shen, Ruiqi and Jie, Guangquan and Liu, Chang and Ding, Henghui}, |
| booktitle={European Conference on Computer Vision (ECCV)}, |
| year={2026} |
| } |
| ``` |