/python-remove-bg-image

python code for remove background image

Primary LanguagePython

python-remove-bg-image

In this session I will share how to remove the background on an image using the rembg module in python. You can maximize the following python code

#Install the rembg module first
pip install rembg
#the process of removing background from input and output state
from rembg import remove
from PIL import Image
input_path = 'assets/travelkoba-python.jpg'
output_path = 'assets/travelkoba-python-rembg.png'
input = Image.open(input_path)
output = remove(input)
output.save(output_path)
#display the results before and after processing
from IPython.display import Image
from IPython.display import display
x = Image(filename='assets/travelkoba-python.jpg', width=200) 
y = Image(filename='assets/travelkoba-python-rembg.png', width=200) 
display(x, y)

Output before & after