We will build a project that can help us in changing the background of any image without using any image editor like Photoshop, etc. This project can be done with the help of some libraries using Python programming.
In this project we will be changing the background of image with the help of some libraries using Python programming.
The details of python libraries and how they are working is here-
LIBRARIES USED
-
Numpy:
numpy
forms the basis of powerful machine learning libraries like scikit-learn and SciPy. As machine learning grows, so does the list of libraries built onnumpy
. TensorFlow’s deep learning capabilities have broad applications — among them speech and image recognition, text-based applications, time-series analysis, and video detection. PyTorch, another deep learning library, is popular among researchers in computer vision and natural language processing. -
OpenCV:
opencv
is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage then Itseez. The library is cross-platform and free for use under the open-source Apache 2 License. -
Matplotlib:
matplotlib
is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK.
Install the following libraries using pip
command in any terminal
pip install numpy
pip install opencv-python
pip install matplotlib
- We are importing the required libraries
- Reading the image as per our choice
- Then applying mask on the image
- Resizing the image, so that both the images can be of same size
- Now with the help of and operation combining the masked image with background image
- After that displaying and saving the final image
To start using this project, follow the below guidelines:
1. Fork this project/repository.
2. Clone your forked copy of the project/repository.
git clone https://github.com/<your-github-username>/Hacking-Scripts.git
3. Navigate to the project directory.
cd Hacking-Scripts/Python/Change Image Background/
4. Install the requirements.txt
using the given command.
pip install -r requirements.txt
5. Run change_image_background.ipynb
file in Google Colab or Jupyter Notebook or any other platform.
1. Sample image for any Object
2. Image for Background
3. Final Output