Code Monkey home page Code Monkey logo

image-matting's Introduction

Imgae matting

Here are a few effects(omitting mask images):

image-1

image-2

How to Run

Method 1: Run from Source Code

Firstly, you need to download the project code and install the required dependencies.

# Python 3.10

git clone https://github.com/ihmily/image-matting.git
cd image-matting
pip install -r requirements.txt

Next, use the following command to run the web interface.

python app.py

Finally, visit http://127.0.0.1:8000/.

Method 2: Run with Docker

Simply run the following commands after entering the project folder.

Pull the Docker image.

docker pull ihmily/image-matting:latest

After the image is pulled, run the container.

docker run -p 8000:8000 ihmily/image-matting:latest

Alternatively, you can build the image yourself.

docker build -t image-matting:latest .
docker run -p 8000:8000 image-matting:latest

Lastly, visit http://127.0.0.1:8000 to perform online image matting. Feel free to choose the method that suits your preference.

Use API

Please run it before use API

File upload

import requests

server = "http://127.0.0.1:8000"
image_path = "image.png"
model_name = "universal"  # people,universal
files = {"image": (image_path, open(image_path, "rb"))}
data = {"model": model_name}
response = requests.post(server+'/matting', files=files, data=data)
print(response.text)
json_data = response.json()
image_url = json_data['result_image_url']
mask_url = json_data['mask_image_url']
print("image_url:", server + image_url)
print("mask_url:", server + mask_url)

Url upload

import requests

server = "http://127.0.0.1:8000"
image_url = "http://your-image-url/demo.png"
data = {"image_url": image_url, "model": "universal"}  # people,universal
response = requests.post(server+'/matting/url', json=data)
print(response.text)
json_data = response.json()
image_url = json_data['result_image_url']
mask_url = json_data['mask_image_url']
print("image_url:",server+image_url)
print("mask_url:",server+mask_url)

You can freely choose the method you want to upload from above.If you want to get the cropped cutout, you can call crop_image_by_alpha_channel function.

Extended Gallery

image-3

image-4

References

https://modelscope.cn/models/damo/cv_unet_universal-matting/summary

https://modelscope.cn/models/damo/cv_unet_image-matting/summary

image-matting's People

Contributors

ihmily avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.