This Jupyter Notebook uses Azure Computer Vision to remove the background from images and visualizes the results using a Gradio web interface. Users can upload an image through the Gradio interface, and the service will return the image with the background removed as well as a mask of the object.
- Python 3.6+
- Azure Subscription
- Azure Computer Vision Service
- Jupyter Notebook
-
Clone the repository
git clone https://github.com/YourRepo/YourProject.git
-
Change to project directory
cd YourProject
-
Install the required packages
pip install gradio pip install requests pip install python-dotenv pip install pillow
-
Set Environment Variables
Create an.env
file in the root folder namedazure.env
. In this file, set your Azure AI Vision API key and endpoint:azure_cv_key=YOUR_AZURE_CV_KEY azure_cv_endpoint=YOUR_AZURE_CV_ENDPOINT
-
Open the Jupyter Notebook file (
your_notebook_name.ipynb
). -
Navigate to the cell that contains the Gradio web interface code.
-
Run the cell to launch the Gradio web interface.
A URL will appear in the output section below the cell. Click on it to access the web interface.
post_request
: Function for sending POST requests to Azure.remove_background_from_image
: Main function to remove background from an image.- Gradio UI in Jupyter Notebook: Code to set up the Gradio web interface within the notebook.
You can use the sample images (piova-01.jpg
, piova-02.jpg
, etc.) provided in the images
directory to test the background removal.
You can use the sample images (piova-01.jpg
, piova-02.jpg
, etc.) provided in the images
directory to test the background removal.
For more code examples and use-cases, you can check out the following repositories:
-
Removing Background Using Azure Computer Vision by Serge Retkowsky
This repository can serve as an additional resource for enhancing and expanding your projects in Python.
View Repository -
Azure ComputerVision BackgroundRemoval in .NET by Ppiova
This repository provides a .NET implementation for removing background using Azure Computer Vision. Feel free to utilize it in your .NET projects.
View Repository