Remove background from single image

Discover how to remove the background from an image using the rembg package's function remove and then save the edited image wherever you want on your computer thanks to the os library.

This notebook was created with MLJAR Studio

MLJAR Studio is Python code editior with interactive code recipes and local AI assistant.
You have code recipes UI displayed at the top of code cells.


There are two more packages to import because we want to show you the effect of removing the background.

# import packages
from IPython.display import display
from PIL import Image
import os
from rembg import remove

We used Show Image piece of code here. Get more information here: How to show image in Jupyter Notebook.

# variables:

# code:
with as i:

This simple piece of code allows you to remove the background from any image and save it in any directory:

# variables:
input_image = "/home/apjanusz/images/goryl.png"
output_image = os.path.join(r"", "gorylOutput.png")

# code:
with open(input_image, "rb") as i:
	with open(output_image, "wb") as o:
		input =
		output = remove(input)

Let us show you the final effect:

# variables:

# code:
with as i:


As you can see, removing the background from image isn't that hard. All you need is a little willingness and a good teacher such as MLJAR Studio.

We will be happy to teach you :)

Recipes used in the remove-single-image-background.ipynb

All code recipes used in this notebook are listed below. You can click them to check their documentation.

Packages used in the remove-single-image-background.ipynb

List of packages that need to be installed in your Python environment to run this notebook. Please note that MLJAR Studio automatically installs and imports required modules for you.



Similar notebooks

List of similar Python notebooks, so you can find more inspiration ๐Ÿ˜Š