About

1.1.0
MIT

Remove background with rembg library

Task: Image matting
remove
background
alpha
matting

This algorithm proposes inference on various models to remove image background. It is based on the rembg library (CPU version only).

Illustration image

🚀 Use with Ikomia API

1. Install Ikomia API

We strongly recommend using a virtual environment. If you're not sure where to start, we offer a tutorial here.

pip install ikomia

2. Create your workflow

from ikomia.dataprocess.workflow import Workflow
from ikomia.utils.displayIO import display
# Init your workflow
wf = Workflow()

# Add the real_esrgan algorithm
algo = wf.add_task(name = 'infer_rembg', auto_connect=True)

# Run on your image
wf.run_on(url="https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_portrait.jpg")

# Inspect your results
display(algo.get_input(0).get_image())
display(algo.get_output(1).get_image())

☀️ Use with Ikomia Studio

Ikomia Studio offers a friendly UI with the same features as the API.

  • If you haven't started using Ikomia Studio yet, download and install it from this page.
  • For additional guidance on getting started with Ikomia Studio, check out this blog post.

📝 Set algorithm parameters

  • model_name (str): name of the model. Default: u2net
  • post_process_mask (bool): enable/disable mask post processing
  • alpha_matting (bool): enable/disable alpha matting
  • alpha_matting_fg_threshold (int): foreground threshold. Default: 240
  • alpha_matting_bg_threshold (int): background threshold. Default: 10
  • alpha_matting_erode_size (int): kernel size for erosion. Default: 10
from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Add algorithm
rembg = wf.add_task(name="infer_rembg", auto_connect=True)

rembg.set_parameters({
"model_name": "isnet-general-use",
"post_process_mask": "False",
"alpha_matting": "True",
"alpha_matting_fg_threshold": "240",
"alpha_matting_bg_threshold": "10",
"alpha_matting_erode_size": "7",
})

# Run on your image
wf.run_on(url="https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_portrait.jpg")

# Inspect your results
display(rembg.get_input(0).get_image())
display(rembg.get_output(1).get_image())

🔍 Explore algorithm outputs

Every algorithm produces specific outputs, yet they can be explored them the same way using the Ikomia API. For a more in-depth understanding of managing algorithm outputs, please refer to the documentation.

from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Add algorithm
algo = wf.add_task(name="infer_rembg", auto_connect=True)

# Run on your image
wf.run_on(url="https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_portrait.jpg")

# Iterate over outputs
for output in algo.get_outputs():
# Print information
print(output)
# Export it to JSON
output.to_json()

Developer

  • Ikomia
    Ikomia

License

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

PermissionsConditionsLimitations

Commercial use

License and copyright notice

Liability

Modification

Warranty

Distribution

Private use

This is not legal advice: this description is for informational purposes only and does not constitute the license itself. Provided by choosealicense.com.