{"id":20812380,"url":"https://github.com/osmr/bgsub","last_synced_at":"2025-05-07T10:42:32.398Z","repository":{"id":131249425,"uuid":"415790086","full_name":"osmr/bgsub","owner":"osmr","description":"Automatic Image Background Subtraction","archived":false,"fork":false,"pushed_at":"2021-10-27T16:25:05.000Z","size":42,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T09:11:18.169Z","etag":null,"topics":["background-subtraction"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osmr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-11T05:29:26.000Z","updated_at":"2024-12-14T13:32:37.000Z","dependencies_parsed_at":"2023-03-10T16:45:55.627Z","dependency_job_id":null,"html_url":"https://github.com/osmr/bgsub","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osmr%2Fbgsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osmr%2Fbgsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osmr%2Fbgsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osmr%2Fbgsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osmr","download_url":"https://codeload.github.com/osmr/bgsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252862133,"owners_count":21815800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["background-subtraction"],"created_at":"2024-11-17T20:53:44.688Z","updated_at":"2025-05-07T10:42:32.390Z","avatar_url":"https://github.com/osmr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Automatic Image Background Subtraction\n\n[![GitHub License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Python Version](https://img.shields.io/badge/python-3.7%2C3.8-lightgrey.svg)](https://github.com/osmr/bgsub)\n\nThis repo contains set of scripts for automatic one-shot image background subtraction task using the following strategies:\n1. the appropriate background subtraction services (mostly human based):\n- [benzin.io](https://benzin.io/),\n- [remove.bg](https://www.remove.bg/).\n2. U-Net human segmentation [net](https://github.com/ternaus/people_segmentation) + CascadePSP refinement [net](https://github.com/hkchengrex/CascadePSP):\n3. BackgroundMattingV2 [net](https://github.com/PeterL1n/BackgroundMattingV2).\n\n## Installation\n```\ngit clone https://github.com/osmr/bgsub.git\ncd bgsub\npip install -r requirements.txt\n```\n\n## Usage\n1. Launch a script for background subtraction via benzin.io/remove.bg service:\n```\npython subtract_bg_service.py --service=\u003cservice\u003e --token=\u003cyour token\u003e --input=\u003cdirectory with images\u003e --output=\u003coutput directory with binary masks\u003e\n```\nHere:\n- `service` is `benzinio` for `benzin.io` service or `removebg` for `remove.bg`,\n- `token` is a service API token value, which you will receive after registering on the selected service,\n- `input` is a directory with processing JPEG images (can contain subdirectories),\n- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).\n\nOptional parameters:\n- `middle` is a directory with intermediate images with original masks obtained from the service (PNG with alpha mask),\n- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).\n- `threshold` is a threshold for mask binarization (default value is 127),\n- `url` is an optional custom URL for service,\n- `jpg` is a flag for forced recompression an input image as JPG (should use as `--jpg`),\n- `not-resize` is a flag for suppressing forcible scale the mask to the input image (should use as `--not-resize`).\n\n2. Launch a script for background subtraction via human segmentation network:\n```\npython subtract_bg_human.py --input=\u003cdirectory with images\u003e --output=\u003coutput directory with binary masks\u003e\n```\nHere:\n- `input` is a directory with processing JPEG images (can contain subdirectories),\n- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).\n\nOptional parameters:\n- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).\n- `use-cuda` is a flag for using CUDA for network inference (should use as `--use-cuda`).\n\n3. Launch a script for background subtraction via matting network:\n```\npython subtract_bg_matting.py --input=\u003cdirectory with images\u003e --bg=\u003cbackground image path\u003e --output=\u003coutput directory with binary masks\u003e\n```\nHere:\n- `input` is a directory with processing JPEG images (can contain subdirectories),\n- `bg` is a background image file path,\n- `output` is a directory with resulted PNG binary masks (it is assumed that all original images had unique names).\n\nOptional parameters:\n- `threshold` is a threshold for mask binarization (default value is 127),\n- `ppdir` is a flag for adding extra parrent+parrent directory to the output one (should use as `--ppdir`).\n- `use-cuda` is a flag for using CUDA for network inference (should use as `--use-cuda`).\n\n## Remark\n\nThe script does not recalculate the masks if the target images already exist.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosmr%2Fbgsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosmr%2Fbgsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosmr%2Fbgsub/lists"}