How to fix black border after remove bg?
vuhaopro90 opened this issue · 3 comments
vuhaopro90 commented
After remove bg I have a proplem, border is black like this [
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)
Gowtham58 commented
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))
github-actions commented
This issue is stale because it has been open for 30 days with no activity.
github-actions commented
This issue was closed because it has been inactive for 14 days since being marked as stale.