├── .gitignore
├── requirements.txt
├── images
├── input
│ ├── 1.jpg
│ └── 2.jpg
└── output
│ ├── 1.png
│ └── 2.png
├── libraries.bat
├── Readme.md
└── main.py
/.gitignore:
--------------------------------------------------------------------------------
1 | images
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | rembg
2 | art
3 | PIL
4 | progress
5 | pathlib
--------------------------------------------------------------------------------
/images/input/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldat/photo_background_removal/HEAD/images/input/1.jpg
--------------------------------------------------------------------------------
/images/input/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldat/photo_background_removal/HEAD/images/input/2.jpg
--------------------------------------------------------------------------------
/images/output/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldat/photo_background_removal/HEAD/images/output/1.png
--------------------------------------------------------------------------------
/images/output/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldat/photo_background_removal/HEAD/images/output/2.png
--------------------------------------------------------------------------------
/libraries.bat:
--------------------------------------------------------------------------------
1 | pip install rembg
2 | pip install art
3 | pip install PIL
4 | pip install progress
5 | pip install pathlib
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # Photo background removal
2 |
3 | ## How to install
4 | 1. Clone this repository on your computer
5 | `https://github.com/paveldat/photo_background_removal.git`
6 | 2. Install all the requirements
7 | `run libraries.bat` or
8 | `pip install -r requirements.txt`
9 | 3. Run the program
10 | `python main.py`
11 |
12 | ## Result
13 | Input:
14 |
15 | Output:
16 |
17 |
18 | Input:
19 |
20 |
Output:
21 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | """
2 | ██▄██ ▄▀▄ █▀▄ █▀▀ . █▀▄ █░█
3 | █░▀░█ █▄█ █░█ █▀▀ . █▀▄ ▀█▀
4 | ▀░░░▀ ▀░▀ ▀▀░ ▀▀▀ . ▀▀░ ░▀░
5 |
6 | ▒▐█▀█─░▄█▀▄─▒▐▌▒▐▌░▐█▀▀▒██░░░░▐█▀█▄─░▄█▀▄─▒█▀█▀█
7 | ▒▐█▄█░▐█▄▄▐█░▒█▒█░░▐█▀▀▒██░░░░▐█▌▐█░▐█▄▄▐█░░▒█░░
8 | ▒▐█░░░▐█─░▐█░▒▀▄▀░░▐█▄▄▒██▄▄█░▐█▄█▀░▐█─░▐█░▒▄█▄░
9 | """
10 | from rembg import remove
11 | from PIL import Image
12 | from pathlib import Path
13 | from art import tprint
14 | from progress.bar import Bar
15 |
16 |
17 | def remove_background():
18 | list_of_extensions = ['*.jpg', '*.png']
19 | all_images = []
20 |
21 | print('Getting list of all files')
22 | for ext in list_of_extensions:
23 | all_images.extend(Path('images/input/').glob(ext))
24 |
25 | with Bar('Removing background...', max=len(all_images)) as bar:
26 | for image_path in all_images:
27 | input_path = Path(image_path)
28 | image = input_path.stem
29 |
30 | output_path = f'images/output/{image}.png'
31 |
32 | input_img = Image.open(input_path)
33 | output_img = remove(input_img)
34 | output_img.save(output_path)
35 | bar.next()
36 |
37 |
38 | def main():
39 | tprint('Remove background')
40 | remove_background()
41 |
42 |
43 | if __name__ == '__main__':
44 | main()
45 |
--------------------------------------------------------------------------------