T.Masuda commited on
Commit
98333cb
·
1 Parent(s): b4dfc05

combine-images

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/background.png filter=lfs diff=lfs merge=lfs -text
37
+ examples/foreground.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rembg import remove
3
+ from PIL import ImageOps, ImageDraw
4
+
5
+ def process_image(foreImg, flip, backImg, left, top, width, height, isLoc):
6
+ if foreImg is None:
7
+ return None
8
+
9
+ if isLoc:
10
+ if backImg is None:
11
+ return None
12
+ rect = ImageDraw.Draw(backImg)
13
+ imwidth = foreImg.width
14
+ imheight = foreImg.height
15
+ if width > 0:
16
+ imwidth = width
17
+ if height > 0:
18
+ imheight = height
19
+ rect.rectangle([(left, top), (imwidth + left, imheight + top)], outline=(255, 0, 0), width=4)
20
+ return backImg
21
+
22
+ image = remove(foreImg)
23
+ if flip:
24
+ image = ImageOps.mirror(image)
25
+
26
+ imwidth = image.width
27
+ imheight = image.height
28
+ if width > 0:
29
+ imwidth = width
30
+ if height > 0:
31
+ imheight = height
32
+ image = image.resize((imwidth, imheight))
33
+
34
+ if backImg is None:
35
+ return image
36
+
37
+ backImg.paste(image, (left, top), image)
38
+ return backImg
39
+
40
+ gr.Interface(
41
+ fn=process_image,
42
+ inputs=[
43
+ gr.Image(label='foreground', type='pil'),
44
+ gr.Checkbox(label='flip left and right'),
45
+ gr.Image(label='background', type='pil'),
46
+ gr.Slider(maximum=4000, step=1, label='left'),
47
+ gr.Slider(maximum=4000, step=1, label='top'),
48
+ gr.Slider(maximum=4000, step=1, label='width'),
49
+ gr.Slider(maximum=4000, step=1, label='height'),
50
+ gr.Checkbox(label='check location only'),
51
+ ],
52
+ title='combine images',
53
+ description='combine images',
54
+ outputs='image',
55
+ allow_flagging='never',
56
+ examples=[['examples/foreground.png', False, 'examples/background.png', 720, 540, 256, 256, False]],
57
+ #cache_examples=False
58
+ ).launch()
examples/background.png ADDED

Git LFS Details

  • SHA256: e25c3266408ade3c4c7767b8e097a7c34cad2be97479e4eed673e7b643d5daba
  • Pointer size: 132 Bytes
  • Size of remote file: 1.28 MB
examples/foreground.png ADDED

Git LFS Details

  • SHA256: 59e832f9d9892a0b335c437b1485c15e8fbc86db96d9b0da0b1c479ead5487f6
  • Pointer size: 132 Bytes
  • Size of remote file: 1.47 MB
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ rembg