rembg
rembg copied to clipboard
How to delete only white color
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()
Update: White to transparency
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.