arvind.vartiya commited on
Commit
dee1947
1 Parent(s): b19d00b

image murge fixed

Browse files
Files changed (1) hide show
  1. app.py +20 -31
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
- Merges two images using the specified method.
7
 
8
- Args:
9
- image1 (PIL.Image): The first image.
10
- image2 (PIL.Image): The second image.
11
- method (str, optional): The method for merging. Defaults to "concatenate".
12
- Supported methods:
13
- - "concatenate": Concatenates the images horizontally.
14
- - "average": Creates an average blend of the two images.
15
- - "custom": Allows for custom logic using (image1, image2) as input.
16
 
17
- Returns:
18
- PIL.Image: The merged image.
19
- """
20
-
21
- if method == "concatenate":
22
- # Concatenate images horizontally
23
- width, height = image1.size
24
- merged_image = Image.new(image1.mode, (width * 2, height))
25
- merged_image.paste(image1, (0, 0))
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(