danielgatis / rembg

Rembg is a tool to remove images background
MIT License
16.48k stars 1.84k forks source link

[BUG] Black background #564

Closed rominasilvera closed 7 months ago

rominasilvera commented 8 months ago

When trying to remove a JPG's background, the returned output is the same picture but the background is painted in black, instead of transparent or white.

Importing modules

from rembg import remove from PIL import Image import numpy as np

Setting path and reading image

input_path = ".venv/Scripts/fotos_exp/AAB_0001.JPG" input_image = Image.open(input_path)

Visualising image

input = Image.open(input_path) print(input.format, input.size, input.mode) # JPEG (2896, 1944) RGB input.show()

AAB_0001

Conversion and saving output file

input_array = np.array(input_image) output_array = remove(input_array) output_image = Image.fromarray(output_array) output_image = output_image.convert('RGB') output_image.save('.venv/Scripts/output_image.png')

output_image

I also tried another method, which consists on not transforming to numpy.array: output = remove(input) output.show() The output was the same

Versions:

pillow 10.2.0 rembg 2.0.53

zhengxiongli08 commented 8 months ago

Hi, rominasilvera. Black is the default background color, because it's (0, 0, 0) in RGB mode. If you want to change the background color, please use the code below,

output = remove(input, bgcolor=(255, 255, 255, 255))

See more from here https://github.com/danielgatis/rembg/blob/main/USAGE.md

github-actions[bot] commented 7 months ago

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

github-actions[bot] commented 7 months ago

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