File size: 1,084 Bytes
1c08271
9846483
 
 
1c08271
9846483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6fe24d
9846483
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from PIL import Image
import rembg
import os

# Function to process the image
def process_image(input_img, background_img):
    input_img = input_img.convert('RGBA')
    background_img = background_img.convert('RGBA')
    background_img = background_img.resize((input_img.width, input_img.height))

    # Remove background using rembg
    output = rembg.remove(input_img)

    combined_img = Image.alpha_composite(output, background_img)

    return combined_img

# Streamlit app
def main():
    st.title("Background Removal and Compositing")

    # Select background image
    background_img_file = st.file_uploader("Select a background image", type=["jpg", "png"])

    if background_img_file is not None:
        # Load input and background images
        background_img = Image.open(background_img_file)

        # Process the images
        #combined_img = process_image(input_img, background_img)

        # Display the combined image
        st.image(background_img, caption="Combined Image", use_column_width=True)

if __name__ == "__main__":
    main()