Spaces:
Runtime error
Runtime error
Commit
·
dee1947
1
Parent(s):
b19d00b
image murge fixed
Browse files
app.py
CHANGED
@@ -1,40 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
|
|
3 |
|
4 |
def merge_images(image1, image2, method="concatenate"):
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
merged_image.paste(image2, (width, 0))
|
27 |
-
elif method == "average":
|
28 |
-
# Create an average blend
|
29 |
-
merged_image = Image.blend(image1, image2, 0.5)
|
30 |
-
elif method == "custom":
|
31 |
-
# Implement your custom logic here, using image1 and image2
|
32 |
-
# This allows for more advanced merging techniques
|
33 |
-
pass
|
34 |
-
else:
|
35 |
-
raise ValueError(f"Unsupported merge method: {method}")
|
36 |
-
|
37 |
-
return merged_image
|
38 |
|
39 |
# Define Gradio interface
|
40 |
interface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
+
import cv2
|
4 |
|
5 |
def merge_images(image1, image2, method="concatenate"):
|
6 |
+
"""
|
7 |
+
Merges two images using the specified method.
|
8 |
|
9 |
+
Args:
|
10 |
+
image1 (PIL.Image): The first image.
|
11 |
+
image2 (PIL.Image): The second image.
|
12 |
+
method (str, optional): The method for merging. Defaults to "concatenate".
|
13 |
+
Supported methods:
|
14 |
+
- "concatenate": Concatenates the images horizontally.
|
15 |
+
- "average": Creates an average blend of the two images.
|
16 |
+
- "custom": Allows for custom logic using (image1, image2) as input.
|
17 |
|
18 |
+
Returns:
|
19 |
+
PIL.Image: The merged image.
|
20 |
+
"""
|
21 |
+
img1 = cv2.resize(image1, (512,512))
|
22 |
+
img2 = cv2.resize(image2, (512,512))
|
23 |
+
img = img1*0.5 + img2*0.5
|
24 |
+
img = img.astype('uint8')
|
25 |
+
|
26 |
+
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Define Gradio interface
|
29 |
interface = gr.Interface(
|