File size: 1,869 Bytes
0831268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
import streamlit as st
from PIL import Image
from texture_transfer import create_image_tile, create_layover, create_image_cutout, paste_image

st.title("Texture Correction App")

if 'clicked' not in st.session_state:
    st.session_state.clicked = False


def click_button():
    st.session_state.clicked = True


with st.sidebar:
    st.text("Play around this values")
    opacity = st.slider("Control opacity", min_value=0.0, max_value=100.0, value=100.0)

product, generated, texture_correct = st.columns(3)
with product:
    st.header("Input product texture patch")
    product_image = st.file_uploader("Patch of the Garment(Cut out an area from the garment)",
                                     type=["png", "jpg", "jpeg"])
    if product_image:
        st.image(product_image)

with generated:
    st.header("Input generated product Image & Mask")
    generated_image = st.file_uploader("Generated Image", type=["png", "jpg", "jpeg"])
    gen_image_mask = st.file_uploader("Generated Mask", type=["png", "jpg", "jpeg"])
    if generated_image:
        st.image(generated_image)

with texture_correct:
    st.button("Texture Correct", on_click=click_button)
    if st.session_state.clicked:
        with st.spinner("Texture correcting🫡..."):
            product_image = Image.open(generated_image)
            product_image_dim = product_image.size
            x_dim = product_image_dim[0]
            y_dim = product_image_dim[0]
            create_image_tile(product_image, x_dim, y_dim)
            overlay = create_layover(generated_image, 'tiled_image.png', opacity)
            create_image_cutout('lay_over_image.png', gen_image_mask)
            paste_image(generated_image, 'cut_out_image.png', gen_image_mask)
            st.image("result.png", caption="Texture Corrected Image", use_column_width=True)