
Background Removal
Background Removal is an image processing technique used to separate the main object from the background of a photo. Removing the background helps highlight the product, subject, or character, bringing a professional and aesthetically pleasing look to the image.
Background Removal
Summary
Introduction
Background Removal is a task in the field of image processing and computer vision. This task aims to remove the background portion from an image, leaving only the main foreground objects. The background is typically unwanted, unnecessary, or distracting elements in an image. Removing the background can help highlight the main subject, easily integrate it into different contexts, or integrate it into various applications.
The Background Removal task can utilize the ModNet model, which is capable of detecting and removing background layers from the original image. This allows you to isolate key objects in the image and utilize them in various applications. With this capability, you can perform tasks such as image stitching, creating special effects, changing backgrounds, and other creative tasks, while saving time and effort compared to manual background separation.
Parameters
Inputs
- input - (image -.png|.jpg|.jpeg): The image data is used by users to remove backgrounds.
Output
- output - (image -.png): The image data has been processed to remove the background.
Examples
input | output |
---|---|
![]() | ![]() |
![]() | ![]() |
Usage for developers
Please find below the details to track the information and access the code for processing the model on our platform.
Requirements
numpy
torch
torchvision
Pillow
Code based on AIOZ structure
import torch, os
from .bg_remove import BGRemove
...
def do_ai_task(
input: Union[str, Path],
model_storage_directory: Union[str, Path],
device: Literal["cpu", "cuda", "gpu"] = "cpu",
*args, **kwargs) -> Any:
"""Define AI task: load model, pre-process, post-process, etc ..."""
# Define AI task workflow. Below is an example
# Load weight
path_weightImage = os.path.join(model_storage_directory, "modnet_photographic_portrait_matting.ckpt")
output_path = "output.png"
bg_remover = BGRemove(path_weightImage)
bg_remover.image(input, background=False, output = output_path)
output = open(output_path, "rb")
return output
Reference
This repository is built upon and inspired by the MODNet, which is a model designed for real-time portrait matting using only RGB image inputs. We extend our sincere appreciation to the creators for generously sharing their code.
License
We respect and comply with the terms of the author's license cited in the Reference section, including the main contents below:
The code, models, and demos in this repository (excluding GIF files under the folder doc/gif) are released under the Apache License 2.0 license.
Citation
@InProceedings{MODNet,
author = {Zhanghan Ke and Jiayu Sun and Kaican Li and Qiong Yan and Rynson W.H. Lau},
title = {MODNet: Real-Time Trimap-Free Portrait Matting via Objective Decomposition},
booktitle = {AAAI},
year = {2022},
}