rembg icon indicating copy to clipboard operation
rembg copied to clipboard

How to delete only white color

Open berik123 opened this issue 2 years ago • 2 comments

Hello, thanks for your work. But I wanted to ask how can I remove only the white color in my pictures? Is there such a possibility? It would help me a lot Here is the code

import os

from rembg import remove from PIL import Image

def remove_bg(place): if not os.path.isdir('images_without_bg'): os.mkdir('images_without_bg') for pict in os.listdir(place): if pict.endswith('.png') or pict.endswith('.png') or pict.endswith('.png'): print(f'[+] Удаляю фон: "{pict}"...') output = remove(Image.open(os.path.join(place, pict))) output.save(os.path.join('images_without_bg', f'{pict.split(".")[0]}.png')) else: continue

def get_target_path(): while not os.path.isdir(user_input := input("[+] Введите путь к папке с изображениями: ")): print(f'Папка "{user_input}" не найдена\n') print(f"\nРаботаем с папкой {user_input}\n") return user_input

def main(): remove_bg(get_target_path()) print('\n[+] Удаление завершено!')

if name == "main": main()

berik123 avatar Jul 08 '22 04:07 berik123

Update: White to transparency

berik123 avatar Jul 08 '22 04:07 berik123

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 08 '22 02:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 22 '22 02:08 github-actions[bot]