Remove Background From an image using PIL and OpenCV in Python

 Remove Background From an image  using PIL, opencv in Python


Introduction: In this blog, we will use python , OpenCV and PIL to remove background from an image using rembg libraray. Make sure to rembg before running this code


pip install rembg


Code:


from rembg import remove
from PIL import Image

input_path = 'input.png'
output_path = 'output.png'

input = Image.open(input_path)
output = remove(input)
output.save(output_path)


With OpenCV

from rembg import remove
import cv2

input_path = 'input.png'
output_path = 'output.png'

input = cv2.imread(input_path)
output = remove(input)
cv2.imwrite(output_path, output)


Results





Post a Comment

0 Comments