Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -50,6 +50,20 @@ def on_random_click():
|
|
50 |
updates.append(texture)
|
51 |
return updates
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def on_image_upload(image):
|
54 |
# Process the uploaded image and get PCA coefficients
|
55 |
coefficients = process_uploaded_image(image)
|
@@ -107,4 +121,4 @@ with gr.Blocks() as demo:
|
|
107 |
outputs=[*sliders, output_image]
|
108 |
)
|
109 |
|
110 |
-
demo.launch()
|
|
|
50 |
updates.append(texture)
|
51 |
return updates
|
52 |
|
53 |
+
def process_uploaded_image(uploaded_image):
|
54 |
+
# Resize the image to match the texture size
|
55 |
+
resized_image = cv2.resize(uploaded_image, (TEXTURE_SIZE, TEXTURE_SIZE))
|
56 |
+
resized_image = cv2.cvtColor(resized_image, cv2.COLOR_RGB2BGR)
|
57 |
+
flattened_image = resized_image.flatten()
|
58 |
+
|
59 |
+
# Project the image into the PCA component space
|
60 |
+
centered_image = flattened_image - mean_texture
|
61 |
+
coefficients = np.dot(centered_image, components.T)
|
62 |
+
|
63 |
+
# Clip the coefficients within the allowed slider ranges
|
64 |
+
clipped_coefficients = [np.clip(coeff, -slider_ranges[i], slider_ranges[i]) for i, coeff in enumerate(coefficients)]
|
65 |
+
return clipped_coefficients
|
66 |
+
|
67 |
def on_image_upload(image):
|
68 |
# Process the uploaded image and get PCA coefficients
|
69 |
coefficients = process_uploaded_image(image)
|
|
|
121 |
outputs=[*sliders, output_image]
|
122 |
)
|
123 |
|
124 |
+
demo.launch()
|