Python desktop app example of remove background from image with OpenCV, PyTorch
You need CUDA to run this.
- pillow - to save the image
- opencv-python - to handle the image file as numpy array and apply Gaussian Blur to make border smooth
- torch - to use CUDA
- torchvision - To use deeplab V3 (prominent image segmenation model made by Google)
- clone this repo.
pip install -r requirements.txt
to download necessary packages- python main.py
- First find the path which including images you want to remove the background.
- This package has the sample folder to make you get proper images (which is generated by Stable Diffusion) more conviniently.
- Press "Remove Background and Save!" button. It will make a backup folder and save original images to it and remove the background from the images in folder.
![](https://private-user-images.githubusercontent.com/55078043/260335294-6cce690f-391f-45b6-84e5-e3fff0add25e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkzMDUxMjcsIm5iZiI6MTcxOTMwNDgyNywicGF0aCI6Ii81NTA3ODA0My8yNjAzMzUyOTQtNmNjZTY5MGYtMzkxZi00NWI2LTg0ZTUtZTNmZmYwYWRkMjVlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI1VDA4NDAyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM1YzgyNTBhNTYxNmY0YzEyODQxMzcxZTNjZDZiYTMxMjU1NzZjMDNiMmUwMzUwMzM4ZGY5Y2U1MjlmNGZkNjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MpJ4tAJce_u1h7MDYSVFlcPLPHKDWGM_6FKZ2IuSJBw)
![](https://private-user-images.githubusercontent.com/55078043/260335291-47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