danielgatis/rembg

How to fix black border after remove bg?

vuhaopro90 opened this issue · 3 comments

After remove bg I have a proplem, border is black like this [
Screenshot 2024-03-13 160352
how to fix it
my code:

from rembg import remove
from PIL import Image, ImageDraw

# Đường dẫn ảnh gốc
input_path = 'du an part 2/DSC04113.jpg'

# Đường dẫn ảnh sau khi loại bỏ nền
output_path = 'du an part 2/goutput.png'

# Đường dẫn ảnh với nền mới
output_with_background_path = 'du an part 2/output.png'

# Màu nền mới (RGB)
new_background_color = (54, 113, 157)  # Màu 36719d

# Loại bỏ nền của ảnh
input_image = Image.open(input_path)
output_image = remove(input_image)


# Tạo ảnh mới với nền màu mới
background_image = Image.new('RGB', output_image.size, new_background_color)
background_image.paste(output_image, (0, 0), output_image)
background_image.save(output_with_background_path)

Hi, @vuhaopro90 try setting alpha_matting parameter to True, like this,

output_image = remove(input_image, alpha_matting=True)

and also you can directly get an image with color background using bgcolor,

output_image = remove(input_image, alpha_matting=True, bgcolor=(54, 113, 157, 255))

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.