Segment Matting is a project aimed at improving the quality and performance of image matting using the SAM (Segment Anything Model) model. It focuses on optimizing the matting process to reduce jagged edges and improve the overall accuracy of the segmentation. This project integrates the capabilities of segment-anything.com and leverages the resources provided by the meta-sam-demo repository.
The Segment Matting project combines the power of the SAM model and the user-friendly interface of segment-anything.com to provide an efficient and accurate solution for image matting. The main objectives of this project are:
- Improve the quality of matting results by reducing jagged edges and improving the smoothness of the segmentation.
- Optimize the performance of the matting process to achieve faster and more efficient results.
- Provide a user-friendly interface for easy interaction and seamless integration with other applications.
To get started with the Segment Matting project, follow these steps:
- Clone the segment-matting repository to your local machine.
$ git clone https://github.com/haibingtown/segment-matting.git
- build the Frontend
- Navigate to the web directory and install the required dependencies:
$ cd web
$ pnpm i
- Export ONNX model.To export the ONNX model, make sure to download the official model before proceeding with this step. Please refer to the previous steps for detailed instructions.
python export_onnx.py --checkpoint model/{your model}.pth --model-type {you model type} --output model/sam.onnx --return-single-mask --quantize-out --output web/public/static/sam_quantized.onnx
- build the frontend:
$ pnpm run build
- Start the Backend
- Navigate to the server directory and install the required dependencies:
$ pip install -r requirements.txt
-
Add model. Download the official model, and then put it into server/model/ folder.
default
orvit_h
: ViT-H SAM model.vit_l
: ViT-L SAM model.vit_b
: ViT-B SAM model.
-
Run the model.py file to start the backend:
$ python model.py
- Access the Application Open your web browser and visit http://localhost:3000/ to access the project. You will see as below, then just click Upload button.
Currently, the alpha-matting algorithm is being used to achieve image cutout. The specific results are as follows:
Mask | Matting Result | |
---|---|---|
Image 1 | ||
Image 2 |
Contributions to the Segment Matting project are welcome.
This project is licensed under the MIT License. Please see the LICENSE file for more details.
We would like to express our gratitude to the developers of the SAM model and the segment-anything.com platform for their valuable contributions to the field of image matting.