I used Segment-Anything to remove background from photos. Doing this process is divided into two:
- Foreground Detection and Segmentation
- Non-foreground(background) Removal
- Source Image : Image entered by the user
- Bounding Box Image : User-entered bounding box
- Segmented Image : Segmentation of the foreground image to be exempted from inference by segment anything
from PIL import Image
img = Image.fromarray(image_rgb)
mask = Image.open("/content/data/mask_2.png")
new_img = Image.new("RGBA", img.size, (0, 0, 0, 0))
for x in range(img.size[0]):
for y in range(img.size[1]):
if mask.getpixel((x,y)) == (255, 255, 255): # Beyaz piksel
new_img.putpixel((x,y), img.getpixel((x,y)))
new_img.save("arkaplansiz_goruntu.png")