/segment-matting

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.

Primary LanguagePython

Segment Matting

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.

Overview

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.

Getting Started

To get started with the Segment Matting project, follow these steps:

  1. Clone the segment-matting repository to your local machine.
   $ git clone https://github.com/haibingtown/segment-matting.git
  1. 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
  1. Start the Backend
  • Navigate to the server directory and install the required dependencies:
    $ pip install -r requirements.txt
    $ python model.py
  1. 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.

img.png

Matting

Currently, the alpha-matting algorithm is being used to achieve image cutout. The specific results are as follows:

Mask Matting Result
Image 1 Mask 1 Result 1
Image 2 Mask 2 Result 2

Contributing

Contributions to the Segment Matting project are welcome.

License

This project is licensed under the MIT License. Please see the LICENSE file for more details.

Acknowledgements

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.