https://github.com/osmr/bgsub
Automatic Image Background Subtraction
https://github.com/osmr/bgsub
background-subtraction
Last synced: about 1 year ago
JSON representation
Automatic Image Background Subtraction
- Host: GitHub
- URL: https://github.com/osmr/bgsub
- Owner: osmr
- License: mit
- Created: 2021-10-11T05:29:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-27T16:25:05.000Z (over 4 years ago)
- Last Synced: 2025-03-31T09:11:18.169Z (about 1 year ago)
- Topics: background-subtraction
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 9
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Automatic Image Background Subtraction
[](https://opensource.org/licenses/MIT)
[](https://github.com/osmr/bgsub)
This repo contains set of scripts for automatic one-shot image background subtraction task using the following strategies:
1. the appropriate background subtraction services (mostly human based):
- [benzin.io](https://benzin.io/),
- [remove.bg](https://www.remove.bg/).
2. U-Net human segmentation [net](https://github.com/ternaus/people_segmentation) + CascadePSP refinement [net](https://github.com/hkchengrex/CascadePSP):
3. BackgroundMattingV2 [net](https://github.com/PeterL1n/BackgroundMattingV2).
## Installation
```
git clone https://github.com/osmr/bgsub.git
cd bgsub
pip install -r requirements.txt
```
## Usage
1. Launch a script for background subtraction via benzin.io/remove.bg service:
```
python subtract_bg_service.py --service= --token= --input= --output=
```
Here:
- `service` is `benzinio` for `benzin.io` service or `removebg` for `remove.bg`,
- `token` is a service API token value, which you will receive after registering on the selected service,
- `input` is a directory with processing JPEG images (can contain subdirectories),
- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).
Optional parameters:
- `middle` is a directory with intermediate images with original masks obtained from the service (PNG with alpha mask),
- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).
- `threshold` is a threshold for mask binarization (default value is 127),
- `url` is an optional custom URL for service,
- `jpg` is a flag for forced recompression an input image as JPG (should use as `--jpg`),
- `not-resize` is a flag for suppressing forcible scale the mask to the input image (should use as `--not-resize`).
2. Launch a script for background subtraction via human segmentation network:
```
python subtract_bg_human.py --input= --output=
```
Here:
- `input` is a directory with processing JPEG images (can contain subdirectories),
- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).
Optional parameters:
- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).
- `use-cuda` is a flag for using CUDA for network inference (should use as `--use-cuda`).
3. Launch a script for background subtraction via matting network:
```
python subtract_bg_matting.py --input= --bg= --output=
```
Here:
- `input` is a directory with processing JPEG images (can contain subdirectories),
- `bg` is a background image file path,
- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).
Optional parameters:
- `threshold` is a threshold for mask binarization (default value is 127),
- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).
- `use-cuda` is a flag for using CUDA for network inference (should use as `--use-cuda`).
## Remark
The script does not recalculate the masks if the target images already exist.