How to remove the Background from an image using Python? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we'll learn how to remove the background of an image using Python. Pillow module: The Pillow library, a derivative of the Python Imaging Library (PIL), aids in giving Python interpreter image processing capabilities. This library offers a wide range of file format support, a productive internal representation, and moderately potent image-processing skills. The core image library was created to provide quick access to data contained in a few fundamental pixel formats. It ought to offer a reliable framework for a broad image processing tool. Execute the following command in the Terminal Window to install it: pip install PillowRembg module: The rembg module is used to remove the background of the given image. Execute the following command in the Terminal Window to install it: pip install rembgSteps to remove the image background using Python Step 1: Import required modules. Step 2: Read the image using the path of the image. Step 3: Open the image using the Image.open() function. Step 4: Remove the background of the image using the remove() function. Step 5: Save the output image using output.save() function. Remove the background of an image using Python To remove the background of an image using Python firstly we have to import the required modules which we have installed using the pip command. Defining two variables "input_path" and "output_path" where input_path stores the path of image of which background to be removed and output_path stores the path where a new image with removed background has to be saved. Now open the image using Image.open() function and then remove the background of the image using the remove() function. In the last step save the processed image at the location stored in output_path using output.save() function. Python3 # Importing Required Modules from rembg import remove from PIL import Image # Store path of the image in the variable input_path input_path = 'E:\C programs\ Remove BackGround\gfgimage.png' # Store path of the output image in the variable output_path output_path = 'E:\C programs\ Remove BackGround\gfgoutput.png' # Processing the image input = Image.open(input_path) # Removing the background from the given Image output = remove(input) #Saving the image in the given path output.save(output_path) Input Image: Input Image: Before removing the Background Output Image: Output Image: After removing the Background Comment More infoAdvertise with us Next Article How to remove the Background from an image using Python? V vishnuppriyan_ Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2022 Image-Processing Practice Tags : python Similar Reads How to make background image transparent using Python? In this article, the task is to create a background transparent of the image in Python Library Required : First Install pillow library on your Python Application before going ahead. Python Imaging Library is a free and open-source additional library for the Python programming language that adds supp 1 min read How to create Word Art from an image using Python? In this article, we are going to learn how to create word art from an image using Python. In this, we are going to take an image as input and then created a similar image in a text form using the characters. We can perform this task with the help of pillow and pywhatkit modules of Python. Pillow Thi 2 min read Removing Black Background and Make Transparent using Python OpenCV In this article, we will discuss how to remove the black background and make it transparent in Python OpenCV. cv2.cvtColor method cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV. Syntax: cv2 2 min read How To Use Images as Backgrounds in Tkinter? Prerequisite: Python GUI â tkinter , Frame In this article, We are going to write a program use image in the background. In Tkinter, there is no in-built function for images, so that it can be used as a background image. It can be done with various methods: Method 1: Using photoimage methods. When i 3 min read How to remove the frame from a Matplotlib figure in Python? A frame in the Matplotlib figure is an object inside which given data is represented using independent Axes. These axes represent left, bottom, right and top which can be visualized by Spines(lines) and ticks. To remove the frame (box around the figure) in Matplotlib we follow the steps. Here firstl 2 min read How to Crop an Image using the Numpy Module? In this article, we are going to learn about the most naive and efficient approach to crop an image without using any additional module. The numpy module is a Python library used for working with arrays, and large data sets. Python does not have any native support for arrays, as opposed to other hig 4 min read How to download an image from a URL in Python Downloading content from its URL is a common task that Web Scrapers or online trackers perform. These URLs or Uniform Resource Locators can contain the web address (or local address) of a webpage, website, image, text document, container files, and many other online resources. It is quite easy to do 3 min read How to open an image from the URL in PIL? In this article, we will learn How to open an image from the URL using the PIL module in python. For the opening of the image from a URL in Python, we need two Packages urllib and Pillow(PIL). Approach:Install the required libraries and then import them. To install use the following commands:pip ins 1 min read Adding borders to the images using Python - OpenCV Image processing is an interesting field in today's era of Artificial Intelligence and Machine Learning. We can see the applications of image processing in our day-to-day life, like whenever we apply filter over any image (selfie) or when we want to apply some effect like blurring the image, etc. I 1 min read How to find width and height of an image using Python? In this article, we are going to discuss how to get the height and width of a particular image. In order to find the height and width of an image, there are two approaches. The first approach is by using the PIL(Pillow) library and the second approach is by using the Open-CV library. Approach 1: PIL 2 min read Like