Alican Akca commited on
Commit
8a23f94
β€’
1 Parent(s): 8105001

for gif processing

Browse files
Files changed (20) hide show
  1. app.py +51 -35
  2. {methods β†’ examples/pixelArt}/combine.py +0 -0
  3. {methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/cartoonize.cpython-37.pyc +0 -0
  4. {methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/cartoonize.cpython-38.pyc +0 -0
  5. {methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/guided_filter.cpython-37.pyc +0 -0
  6. {methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/network.cpython-37.pyc +0 -0
  7. {methods β†’ examples/pixelArt}/white_box_cartoonizer/cartoonize.py +0 -0
  8. {methods β†’ examples/pixelArt}/white_box_cartoonizer/components/__pycache__/guided_filter.cpython-38.pyc +0 -0
  9. {methods β†’ examples/pixelArt}/white_box_cartoonizer/components/__pycache__/network.cpython-38.pyc +0 -0
  10. {methods β†’ examples/pixelArt}/white_box_cartoonizer/components/guided_filter.py +0 -0
  11. {methods β†’ examples/pixelArt}/white_box_cartoonizer/components/network.py +0 -0
  12. {methods β†’ examples/pixelArt}/white_box_cartoonizer/saved_models/checkpoint +0 -0
  13. {methods β†’ examples/pixelArt}/white_box_cartoonizer/saved_models/model-33999.index +0 -0
  14. {methods β†’ examples/pixelArt}/white_box_cartoonizer/test.jpg +0 -0
  15. methods/__pycache__/combine.cpython-38.pyc +0 -0
  16. methods/__pycache__/img2pixl.cpython-38.pyc +0 -0
  17. methods/__pycache__/instructor.cpython-38.pyc +0 -0
  18. methods/__pycache__/parse.cpython-38.pyc +0 -0
  19. methods/secondMethod.py +0 -12
  20. methods/white_box_cartoonizer/saved_models/model-33999.data-00000-of-00001 +0 -3
app.py CHANGED
@@ -1,53 +1,69 @@
1
  import cv2
2
  import numpy as np
3
  import gradio as gr
 
4
  import paddlehub as hub
5
  from methods.img2pixl import pixL
6
- from methods.combine import combine
7
- from methods.white_box_cartoonizer.cartoonize import WB_Cartoonize
8
  model = hub.Module(name='U2Net')
9
  pixl = pixL()
10
  combine = combine()
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def func_tab1(image,pixel_size, checkbox1):
13
- image = cv2.imread(image.name)
14
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
15
- image = WB_Cartoonize().infer(image)
16
- image = np.array(image)
17
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
18
- if checkbox1:
19
- result = model.Segmentation(
20
- images=[image],
21
- paths=None,
22
- batch_size=1,
23
- input_size=320,
24
- output_dir='output',
25
- visualization=True)
26
- result = combine.combiner(images = pixl.toThePixL([result[0]['front'][:,:,::-1], result[0]['mask']],
27
- pixel_size),
28
- background_image = image)
29
  else:
30
- result = pixl.toThePixL([image], pixel_size)
31
- return result
32
-
33
- def func_tab2():
34
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  inputs_tab1 = [gr.inputs.Image(type='file', label="Image"),
37
  gr.Slider(4, 100, value=12, step = 2, label="Pixel Size"),
38
  gr.Checkbox(label="Object-Oriented Inference", value=False)]
39
- outputs_tab1 = [gr.Image(type="numpy",label="Front")]
40
 
41
- inputs_tab2 = [gr.Video()]
42
- outputs_tab2 = [gr.Video()]
43
-
44
- tab1 = gr.Interface(fn = func_tab1,
45
  inputs = inputs_tab1,
46
- outputs = outputs_tab1)
47
- #Pixera for Videos
48
- tab2 = gr.Interface(fn = func_tab2,
49
- inputs = inputs_tab2,
50
- outputs = outputs_tab2)
51
-
52
- gr.TabbedInterface([tab1], ["Pixera for Images"]).launch()
53
 
 
1
  import cv2
2
  import numpy as np
3
  import gradio as gr
4
+ from PIL import Image
5
  import paddlehub as hub
6
  from methods.img2pixl import pixL
7
+ from examples.pixelArt.combine import combine
8
+ from examples.pixelArt.white_box_cartoonizer.cartoonize import WB_Cartoonize
9
  model = hub.Module(name='U2Net')
10
  pixl = pixL()
11
  combine = combine()
12
 
13
+ def GIF(fname,pixel_size):
14
+ print(fname)
15
+ gif = Image.open(fname)
16
+ frames = []
17
+ for i in range(gif.n_frames):
18
+ gif.seek(i)
19
+ frame = Image.new('RGB', gif.size)
20
+ frame.paste(gif)
21
+ frame = np.array(frame)
22
+ frames.append(frame)
23
+ print(len(frames))
24
+
25
+ result = pixl.toThePixL(frames, pixel_size)
26
+ print(len(result), result[0].shape)
27
+ frames = []
28
+ for frame in result:
29
+
30
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
31
+ frame = Image.fromarray(frame)
32
+ frames.append(frame)
33
+ print(type(frames), len(frames), type(frames[0]), frames[0].size)
34
+ frames[0].save('new.gif', append_images=frames, save_all=True, loop=1)
35
+ return Image.open('cache.gif')
36
+
37
  def func_tab1(image,pixel_size, checkbox1):
38
+ if image.name.endswith('.gif'):
39
+ GIF(image.name,pixel_size)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  else:
41
+ image = cv2.imread(image.name)
42
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
43
+ image = WB_Cartoonize().infer(image)
44
+ image = np.array(image)
45
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
46
+ if checkbox1:
47
+ result = model.Segmentation(
48
+ images=[image],
49
+ paths=None,
50
+ batch_size=1,
51
+ input_size=320,
52
+ output_dir='output',
53
+ visualization=True)
54
+ result = combine.combiner(images = pixl.toThePixL([result[0]['front'][:,:,::-1], result[0]['mask']],
55
+ pixel_size),
56
+ background_image = image)
57
+ else:
58
+ result = pixl.toThePixL([image], pixel_size)
59
+ return result
60
 
61
  inputs_tab1 = [gr.inputs.Image(type='file', label="Image"),
62
  gr.Slider(4, 100, value=12, step = 2, label="Pixel Size"),
63
  gr.Checkbox(label="Object-Oriented Inference", value=False)]
64
+ outputs_tab1 = [gr.Image(type="file",label="Front")]
65
 
66
+ gr.Interface(fn = func_tab1,
 
 
 
67
  inputs = inputs_tab1,
68
+ outputs = outputs_tab1).launch()
 
 
 
 
 
 
69
 
{methods β†’ examples/pixelArt}/combine.py RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/cartoonize.cpython-37.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/cartoonize.cpython-38.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/guided_filter.cpython-37.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/__pycache__/network.cpython-37.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/cartoonize.py RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/components/__pycache__/guided_filter.cpython-38.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/components/__pycache__/network.cpython-38.pyc RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/components/guided_filter.py RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/components/network.py RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/saved_models/checkpoint RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/saved_models/model-33999.index RENAMED
File without changes
{methods β†’ examples/pixelArt}/white_box_cartoonizer/test.jpg RENAMED
File without changes
methods/__pycache__/combine.cpython-38.pyc DELETED
Binary file (1.25 kB)
 
methods/__pycache__/img2pixl.cpython-38.pyc DELETED
Binary file (2.37 kB)
 
methods/__pycache__/instructor.cpython-38.pyc DELETED
Binary file (1.33 kB)
 
methods/__pycache__/parse.cpython-38.pyc DELETED
Binary file (1.32 kB)
 
methods/secondMethod.py DELETED
@@ -1,12 +0,0 @@
1
- import numpy as np
2
- import cv2 as cv
3
- from matplotlib import pyplot as plt
4
- import os
5
-
6
- os.chdir("C:\\Users\Alican Akca\\OneDrive - Izmir Universtiy of Economics\\Belgeler\\GitHub\\pixera")
7
- img = cv.imread(f'{os.getcwd()}\original\1.jpg',0)
8
- edges = cv.Canny(img,100,200)
9
-
10
- plt.subplot(122),plt.imshow(edges,cmap = 'gray')
11
- plt.title('Edge Image'), plt.xticks([]), plt.yticks([])
12
- plt.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
methods/white_box_cartoonizer/saved_models/model-33999.data-00000-of-00001 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:1e2df1a5aa86faa4f979720bfc2436f79333a480876f8d6790b7671cf50fe75b
3
- size 5868300